I'm deploying a site using capistrano to DigitalOcean, and I'm stuck with a problem where some images don't display. I say some, because some do display properly (with the right assets/... URL) while some images in the same div don't display (instead trying to access some images/... path).
The weird part is these images are all in the same folder (assets/images), used in the same each loop, all using the <%= image_tag %> tag.
During deployment, rake assets:precompile always succeeds and there's no visible error.
And lastly, here's a part of my production.rb file:
config.serve_static_assets = false
config.assets.compile = true
config.assets.digest = true
config.assets.version = '1.0'
If you need any other code snippets, let me know and I'll provide them asap.
EDIT:
Changing config.serve_static_assets = false to config.serve_static_assets = true doesn't change the result in any way.
Related
Rails: 4.2.7.1, Ruby: 2.3.1
We used to use non-hashed assets for serving our assets on our multi-site application by hardcoding the path to the asset in the individual site's headers. We are now pre-compiling hashed assets with Sprockets on each deploy in production with these settings:
production.rb
config.consider_all_requests_local = false
config.action_controller.perform_caching = true
config.serve_static_files = true
config.assets.prefix = "/assets"
config.assets.digest = true
config.assets.initialize_on_precompile = true
We end up with hashed assets, for example, in /public/assets/skins/site1/skin-70ee38249235f8521a243a8f955ed08c.css.
We have a skin file for each path that we use to load our styles per site. We do generate a site application.css that remains unused. Each skin file contains variables for each site and then imports the site's manifest file containing the sass stylesheets.
What we tried to do was create a way for our CMS to look for the hashed asset:
stylesheet_link_tag("/assets/skins/site1/skin.css", media: "all")
The issue is that the site is still looking for the non-hashed skin file. If we have the plain skin.css, it will work.
Same goes for Javascript:
javascript_include_tag "/assets/admin.js"
It will look for the non-hashed asset, even though the hashed asset is present. I tried to remove the "/assets" part from the link tags and it will fail.
Is there a setting that we are missing to have Rails look for the proper hashed asset? Any advice is appreciated.
In development it seemed to work well, I used to load the files like this:
$(".div").load("/assets/svg_file.svg");
But now that I have pushed the project to Heroku, it gave me a 404 error inside my console. It also happened with some images I included, but it was fixed by changing the default html image tag to this:
<%= image_tag("logo.png") %>
Since I can't include any ruby code on the client side, how do I do it?
If any user faces the same issue, go to production.rb file (config => environments => production.rb) and change config.assets.compile = false to config.assets.compile = true. This should fix it.
I'm getting duplicate asset fingerprint javascript file on Heroku production.
This initially creates around 3-4 files then after a while (a day), it creates another set of those files again. Also every time I refresh those files get rotated in the source.
On production.rb:
config.assets.enabled = true
config.assets.digest = true
config.action_controller.asset_host = "//#{ENV['FOG_DIRECTORY']}.s3.amazonaws.com"
config.assets.initialize_on_precompile = true
config.assets.precompile += %w( '.woff', '.eot', '.svg', '.ttf', '*.css.scss', application_user.js, popcorn.js )
On application.rb:
config.assets.enabled = true
config.assets.digest = true
Surely this doesn't matter?
Structure
The Rails structure is such that it should allow you to use whatever fingerprinted file you need, and it will show (using the dynamic javascript include helpers)
If you're unable to read a particular file because it's not exactly the same as it was before is, in my opinion, a highlight of a poor system design
Files
I think I remember your issue from another day -- you can just use the helper method to call the files you need. It shouldn't cause any issues with the different names. It's all part of the asset pipeline
I'd recommend looking into how you're calling the files - if you're trying to call the hashed filename directly, you're going to have an issue
All my javascripts stopped working in production when I compiled them into application.js. I fixed this issue by turning asset debug on in production like so:
config.serve_static_assets = false
# Compress JavaScripts and CSS
config.assets.compress = false
# Don't fallback to assets pipeline if a precompiled asset is missed
config.assets.compile = true
# Generate digests for assets URLs
config.assets.digest = true
config.assets.debug = true
my question is if there are any problems with leaving asset debug on in production mode besides people being able to see my js files. Is there a setting I'm missing that would allow me to compress the JS and it still would work? I'd like to be able to compress them but the javascript just isn't loading when I try it.
Sometimes compressed js just doesn't work, could be because of the order it was done, or something else.
I have a quite a big jpg image file and few css files, and these are not going to change for every reload but every time it is loading the full imgae instead of caching in the browser, I tried changing the config like config.action_controller.perform_caching = true etc but nothing seems to help. Is there a way to do that?
This worked for me in my production.rb:
config.serve_static_assets = true
config.static_cache_control = "public, max-age=2419200"
That is 4 weeks which I figure is good enough.