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.
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.