Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialMelinda Golden
Full Stack JavaScript Techdegree Graduate 25,815 PointsMake website not cache images or CSS files
How do I make a website not cache images or CSS files? I constantly have to tell people to clear their browser cache when I make changes to their website and I was wondering if there was a good way to force their browser to clear the cache or always get the fresh files from the server. Thanks!
2 Answers
Steven Parker
231,269 PointsYour server should add these settings to the HTTP header:
Cache-Control: no-cache, no-store, must-revalidate
Pragma: no-cache
Expires: 0
Some browsers will respond to just one of these, but adding them all gives you the best chance with all browsers.
michael lynch
9,560 PointsI though these where helpful shortcuts, not an answer to you question but can be useful.
Hard Refresh - clears browser cache for a specific page and reloads.
Chrome:
Windows = Hold down Ctrl and click the Reload button.
Mac = Hold ⇧ Shift and click the Reload button
FireFox:
Windows = Hold the Ctrl key and press the F5 key
Mac = Hold down the ⇧ Shift and click the Reload button.
Jenn Turner
2,093 PointsJenn Turner
2,093 PointsWhat language is this/ would this go in the .html or .css file? I just started Javascript so this solution sounds way over my head, but I'm having a similar issue with browsers caching old versions of a website I just made for my wedding, so it would be GREAT if I could learn this specific skill sooner rather than later. Thanks!
Steven Parker
231,269 PointsSteven Parker
231,269 PointsThese are HTTP protocol headers, not part of the page code (neither HTML nor CSS). They would get set up in the server configuration.