Disable Browser Cache

lmswimx2

New Member
Messages
2
Reaction score
0
Points
1
I've tried every piece of PHP code to disable browser caching, however, none of them worked. I don't know how to reload the css or js files from my browser after I update them. Unless I delete my browser history, I cannot make it look like it's suppose to after I upload the updated css files. Please help!!!
 

Dead-i

x10Hosting Support Ninja
Community Support
Messages
6,084
Reaction score
367
Points
83
Have you tried using the HTML <meta> tags on your HTML page to stop browser caching? :)

[Moved to Programming, as this is not directly hosting-related]
 

lmswimx2

New Member
Messages
2
Reaction score
0
Points
1
I've tried meta html code and header php code

I've done
<meta http-equiv="Pragma"content="no-cache">
but it didn't work

For example, if I use google chrome and i go to the site. Then i upload a new css file. The i go back to google chrome and i load the site again, it'll still load the old css file, a.k.a. browser cache. However, if I open it in incognito mode in google chrome, it will load the new css file.
 
Last edited:

essellar

Community Advocate
Community Support
Messages
3,295
Reaction score
227
Points
63
In general, you don't want to disable browser cache for elements that should be static in a production environment. (And, really, you don't want to be doing development in a production environment either. In a local dev/test environment, you can globally set all of the cache parameters on your web server to "total amnesia" without incurring any real costs, but on a public-facing server that would be the equivalent of saying "who needs an 8-core Xeon when we have a perfectly good 486SX/25 box lying around?") You do have some real control using .htaccess to set cache-control headers, but that won't help a lot if the asset is already stuck in cache. Locally, you can either force a refresh (Ctrl-F5 twice usually does it in Chrome; Ctrl-F5 once works in most other browsers) or selectively delete your site (and your site only) from your history. In production, one would normally use a versioned file name to ensure that other users get the changes immediately without a refresh.
 

leafypiggy

Manager of Pens and Office Supplies
Staff member
Messages
3,819
Reaction score
163
Points
63
Or, do something like file.css?12389123 when you include it in development. where the numbers are randomly generated from PHP. This will ensure it loads an uncached version every time.
 
Top