Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I exempt images from Rails cache-busting?

I've implemented this solution to help prevent browser page caching, based on the question How to prevent browser page caching in Rails:

def set_cache_buster
    response.headers["Cache-Control"] = "no-cache, no-store, max-age=0, must-revalidate"
    response.headers["Pragma"] = "no-cache"
    response.headers["Expires"] = "Fri, 01 Jan 1990 00:00:00 GMT"
end

While this certainly work, it feels a bit like killing an ant with a sledgehammer; everything is prevent from caching, including images (e.g., a hamburger icon, or other small images like that). When navigating from page to page, this results in unsightly flashes of empty content while these images are reloaded.

Is there a way that I can prevent general caching, but exempt certain assets?

like image 342
Rob Avatar asked Apr 24 '15 13:04

Rob


1 Answers

Sorry for miss on tags, but as i see nginx can be a perfect answer to it - just serve static content (images/css/etc) with nginx and pass all other requests to backend (ruby)

like image 72
He11ion Avatar answered Sep 24 '22 21:09

He11ion