Hi,
I am stuck in a weird situation where in my production environment, an
asset is being attempted to compress while rendering a view.
I’ve all my assets put into public/assets folder via rake
“assets:precompile”
production.rb has following configurations:
Disable live compilation of assets(Don’t fallback to assets pipeline
if
a precompiled asset is missed)
config.assets.compile = false
Assets pre-compilation task(rake assets:precompile) configurations
config.assets.css_compressor = :yui
config.assets.js_compressor = :yui
config.assets.compress = true
When I request for some page let say http://www.example.com/home, while
generating the page response, Rails is trying to compress an asset named
“jquery.bxslider.min”
I’ve following code that is creating error.
<%= content_for :js_include do %>
<%= javascript_include_tag ‘jquery.bxslider.min’ %>
<% end %>
Error in log:
ActionView::Template::Error (undefined method `exitstatus’ for
nil:NilClass
(in /example/lib/assets/javascripts/jquery.bxslider.min.js)):
57: <%= content_for :js_include do %>
58: <%= javascript_include_tag ‘jquery.bxslider.min’ %>
59: <% end %>
The error is however for missing java(as I’m using YUI for compression,
which depends on java)
I don’t want any live compression & compilation, as assets are already
available in public/assets folder
I am surprised, why Rails is trying to compress asset while rendering an
action.
Please advise.
Regards
Farukh D M
On Thursday, July 11, 2013 7:24:34 AM UTC-4, farukhdm wrote:
Disable live compilation of assets(Don’t fallback to assets pipeline if
generating the page response, Rails is trying to compress an asset named
ActionView::Template::Error (undefined method `exitstatus’ for nil:NilClass
I am surprised, why Rails is trying to compress asset while rendering an action.
Please advise.
Regards
Farukh D M
I’m not surprised it is re-compiling the source code at runtime. You
have
to be careful with javascript_include_tag when you are using the asset
pipeline. When you precompile your assets, everything is put into one
js
file with a long, cryptic name that looks something like the following
in
html:
When you then insert a javascript tag, it’s going to look like the
following in your html:
The browser is going to attempt to load both files. It doesn’t detect
that
the contents of jquery.bxslider.min.js are actually already in the first
file. Because this file is located in the /app/assets/js directory,
it’s
going to be processed by rails through the asset compiler when the
browser
requests the file.
You shouldn’t reference a javascript file in a script tag if you’ve
already
included it in the asset pipeline unless you truly intend to load it
twice.
If you have javascript you want to load independent of the asset
pipeline
and you don’t want it processed through the asset compiler, you should
reference it in a javascript_include_tag as you have done above, but you
should locate the file in the public/js directory.
Thanks for the update.
jquery.bxslider.min.js in my case is not part of application.js
I have added jquery.bxslider.min.js to pre-compile path also, so that it
can be loaded independently.
Its available in public/assets folder too.
You said “I’m not surprised it is re-compiling the source code at
runtime.”…I totally agree.
However that should happen when browser request that very particular
asset,
not while creating page response that has
in the markup.
Am I going astray here in making you understand the issue.
Let me know.
On Friday, July 12, 2013 2:07:55 AM UTC-4, farukhdm wrote:
config.assets.compress = true
can be loaded independently.
Hi,
config.assets.compile = false
“jquery.bxslider.min”
(in /example/lib/assets/javascripts/jquery.bxslider.min.js)):
I am surprised, why Rails is trying to compress asset while rendering an
action.
I’m not surprised it is re-compiling the source code at runtime. You
it twice.
You’re right, I didn’t fully understand the issue. The settings in your
production.rb are typical production settings. However, in this case,
the
first setting, config.assets.compile = false has implications.
When this is set to false, the system assumes all assets have been
pre-compiled. When you pre-compile, a manifest is generated that maps
the
“normal” file names to the cryptic filename it’s now compressed into.
When
html code is generated from a view, it references the manifest, and
substitutes the cryptic filename.
This is the point where I’m unsure of what happens. In your case,
there’s
a file referenced in the assets directory that isn’t in the manifest and
isn’t pre-compiled. I’m not sure what the system does because when this
flag is set to false, it doesn’t even load the pipeline gems so it
doesn’t
have access to the compiler. I’m guessing it throws an error, but
that’s a
guess, which would be the error you encountered.
I’d have to test this but my guess is that you either need to
pre-compile
the asset, or locate it in the public directory (only) and write the tag
to
access the file in the public directory.
I’m not sure this is correct, but hopefully it will point you in the
right
direction.
Following are the configurations in my production.rb file:
Disable live compilation of assets(Don’t fallback to assets pipeline
if
a precompiled asset is missed)
config.assets.compile = false
Assets pre-compilation task(rake assets:precompile) configurations
config.assets.css_compressor = :yui
config.assets.js_compressor = :yui
config.assets.compress = true
Let me know, if these configs are specified correctly.
Hey,
Thanks for enlightenment 
I shall perform some ups and downs.
Will let you know, if I get any new insight
Hi,
FYI…
With config.assets.compile = false(live compilation disabled)
I removed entry from manifest.yml file and I got:
ActionView::Template::Error (jquery.bxslider.min.js isn’t precompiled)
which I guess it valid error message.
Had there been, config.assets.compile = true + missing mappin in
manifest
and no java to support YUI gem to compress.
Not sure what would happen.