Reputation: 127
I would like to cache images, but not certain files like CSS and JS. I only found out how to not cache everything, is there a way to selectively cache whichever I want?
// meta tags to not store cache
<meta http-equiv="Cache-control" content="no-cache">
<meta http-equiv="Expires" content="-1">
// force reload cache in JS
location.reload(true);
Upvotes: 1
Views: 353
Reputation: 1075925
You do this with server configuration, not JavaScript or meta tags. Configure your server to return far-futures cache headers for images, but Cache-Control: must-revalidate
and such for JS and CSS.
But seriously consider whether you really want to force your users to re-request the JS and CSS on every page visit. Assuming the HTML content changes regularly, it may be better to just make them revalidate the HTML, and use versioned paths to the JS (script.v2.js
vs. script.v3.js
) and CSS (style.v2.css
vs. style.v3.css
) served with far-futures expires headers. The HTML entry page can then refer to the up-to-date versions of the files when you change them.
Upvotes: 2