Question

I am using the asset_sync gem to upload my assets to an s3 bucket. When running yslow on my website i get a list of images that have no expiry header.Now i can set these manually but when you have a mass amount if images that could take a while..

Is there anyway to set an expiry when running rake assets:precompile for example automatically? Is there anything in the asset_sync config that allows us to do this?

Thanks

Was it helpful?

Solution

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top