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 trial

General Discussion

Melinda Golden
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Melinda Golden
Full Stack JavaScript Techdegree Graduate 25,815 Points

Make 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
Steven Parker
231,007 Points

Your 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.

Jenn Turner
Jenn Turner
2,093 Points

What 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
Steven Parker
231,007 Points

These are HTTP protocol headers, not part of the page code (neither HTML nor CSS). They would get set up in the server configuration.

I 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.