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 Answers3

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

Or Assayag
  • 3,141
  • 8
  • 30
  • 52
  • hey man thanks for the feedback, so put this code in every html file (inside the )? – thehunterbat Jan 08 '21 at 21:50
  • Yea it should do the trick. Don't forget - Each time you upload change the `v=` part to different number – Or Assayag Jan 08 '21 at 21:51
  • 1
    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. – JakeAve Jan 08 '21 at 21:55
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

ManuTheCoder
  • 198
  • 2
  • 9
1

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.

MBiabanpour
  • 199
  • 10