3

I have a simple website with css and html, everytime I upload new content it takes days to refresh. Is there a line of code that forces the browser to reload my code? I have a pdf link which changes week to week. I don't know if to force the entire code or just force the pdf link. Thanks

3 Answers 3

2

Please check the following link: How do we control web page caching, across all browsers?

There are different ways to do that:

If you want to use a htaccess file, add the following line to it:

<IfModule mod_headers.c>
  Header set Cache-Control "no-cache, no-store, must-revalidate"
  Header set Pragma "no-cache"
  Header set Expires 0
</IfModule>

And if you want to just do that in the main html file, add the following to it within the head tag:

<meta http-equiv="Cache-Control" content="no-cache, no-store, must-revalidate">
<meta http-equiv="Pragma" content="no-cache">
<meta http-equiv="Expires" content="0">

I hope my answer helps you.

Sign up to request clarification or add additional context in comments.

1 Comment

The only problem is that it affects the performance of the website (The page will take longer to load)
1

You can add parameters to your static files, like:

<script src="your-source-here.js?v=34535" />

Same goes for other files.

For more advanced solutions: How to force the browser to reload cached CSS and JavaScript files

3 Comments

hey man thanks for the feedback, so put this code in every html file (inside the <head>)?
Yea it should do the trick. Don't forget - Each time you upload change the v= part to different number
I also tend to keep my dev tools with the "disable cache" always on. It's caused me a couple issues, but overall it's way easier while developing.
1

Use CTRL + SHIFT + R to reload

What chrome does is, when you load the page, it loads the external scripts. The first time you load the scripts, it caches it, so that it won't have to load it every single time. To clear the cache, use CTRL SHIFT R

Check this out: Clear the cache in JavaScript

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.