Every time i update my javascript and css files on my website the user have to clear his/her browsing history , cache etc from its browser so i want to update my cache on user browser on regular basis
Asked
Active
Viewed 370 times
0
-
1Whats setting the headers? Maybe look into using a service worker. – Lawrence Cherone Apr 05 '19 at 06:59
-
1Depending of the technique you use, there is mostly a way to make sure your assets won't be cached during development. Please give more information. What browser, what do you use to develop your site? (Framework/webserver, the full stack pls) – Sander Toonen Apr 05 '19 at 07:00
-
Do you only want a solution for the JS and CSS files caching in the browser? – Ropali Munshi Apr 05 '19 at 07:02
1 Answers
3
The most common way to resolve this problem is to add a version string to the end of the script file request.
For example when you got:
<script src="myscripts.js"></script>
Change it to:
<script src="myscripts.js?v=999"></script>
Or a unix timestamp:
<script src="myscripts.js?dt=:unix_timestamp:"></script>
Works the same way with css
files.
You can also add a header entry to your HTML
code (head
section):
<meta http-equiv="Cache-control" content=":value:">
The value
can be:
Public
- may be cached in public shared caches.Private
- may only be cached in private cacheNo-Cache
- may not be cachedNo-Store
- may be cached but not archived
You can also do the above in HTTP
response headers.
For example:
Cache-control: no-cache
Or set a cache lifespan in seconds
Cache-control: max-age=60

Flash Thunder
- 11,672
- 8
- 47
- 91