Rails 4.0.3 Generating Incorrect Asset Paths with Asset_Sync

asset_sync digest URLs not working on production

Hopefully this will help save my fellow programmer friends some head banging :D. I have answered this question on "digest_path & asset_digest_path not allowing digest URLs" but will repost it here so it will save you some clicks.

I was uploading the files to S3, I didn't realize that the manifest wasn't loaded by Rails. You can have all your production settings right (like above and in other threads), but if you don't have the manifest.json file readable by Rails, it will still generate /javascript/* (example) urls.

I was still having trouble with multi_json gem's latest version, so I downgraded it to 1.7.8 and it works fine.

gem 'multi_json', '1.7.8'

That's so it can read the manifest.json file which rake assets:precompile creates.

There is a debate on this sprockets thread https://github.com/rails/sprockets-rails/issues/107 on whether your manifest file should be in git or just on a deploy script, do what suits you best, just make sure it is findable in:

/public/assets/manifest.json 

or specifiy it yourself with

config.assets.manifest = '...'

That may or may not be depricated.

Cheers!

Rails generate incorrect asset path with set 'config.assets.compile = false'

You need to execute RAILS_ENV=production rake assets:precompile manually if the config.assets.compile is set to false.

digest_path & asset_digest_path not allowing digest URLs

Hopefully this will help save my fellow programmer friends some head banging :D

I was uploading the files to S3, I didn't realize that the manifest wasn't loaded by Rails. You can have all your production settings right (like above and in other threads), but if you don't have the manifest.json file readable by Rails, it will still generate /javascript/* (example) urls.

I was still having trouble with multi_json gem's latest version, so I downgraded it to 1.7.8 and it works fine.

gem 'multi_json', '1.7.8'

That's so it can read the manifest.json file which rake assets:precompile creates.

There is a debate on this sprockets thread https://github.com/rails/sprockets-rails/issues/107 on whether your manifest file should be in git or just on a deploy script, do what suits you best, just make sure it is findable in:

/public/assets/manifest.json 

or specifiy it yourself with

config.assets.manifest = '...'

That may or may not be depricated.

Cheers!

Set Expiry Headers asset_sync

Ok so i will answer this.. asset_sync will set cache_control and expiry dates on all assets that have been gzipped. I have noticed though that if some assets are being rendered from within a css file ( background image) then these images are not given any cache or expiry.

So within your asset_sync.rb file you can set custom headers like so

config.custom_headers = { '.*' => { cache_control: 'max-age=315576000', expires: 1.year.from_now.httpdate } }

Feel free to change the regular expression to match your files and change the cache_control and expiry dates.

A big thanks to Benjamin Darfler for pointing this out to me

Missing assets on production mode - passenger on nginx

Try using image-url instead of url.

background: #fff image-url('wallpaper.jpg') top left;

From the Asset Pipeline documentation:

When using the asset pipeline, paths to assets must be re-written and
sass-rails provides -url and -path helpers (hyphenated in Sass,
underscored in Ruby) for the following asset classes: image, font,
video, audio, JavaScript and stylesheet.



Related Topics



Leave a reply



Submit