Cache clearing in php website

karthik80c
karthik80c used Ask the Experts™
on
My website is looking different in different websites. Any update on CSS is not reflecting immediately in firefox but where as safari and chrome show the modification immediately.
Is there a way to add a code which clears the existing cache whenever the website loads and uses the latest style sheet.
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®

Commented:
This is done either in the http server through the .htaccess file:

Header set Cache-Control "no-cache, no-store"

or through PHP:

header('Cache-Control: no-cache, no-store');
Top Expert 2013

Commented:
However there is one big limitation; User Settings.  

You have no control over the user setting and the the browser will not refresh cache if the user settings explicitly prevent it;  unfortunately many users have restricted cache setting to optimize response time, especially if they are on a slow connection or use a lot of sites heavy on graphics or videos.

Cd&

Author

Commented:
Thank you Computer and Coboldinosaur.
Coboldinosaur
- then so what would be the best solution for this Coboldinosaur. Please let me know.

Thanks
Fixer of Problems
Most Valuable Expert 2014
Commented:
When I change files that like CSS and javascript that are part of an HTML page, I often change the names of the files.  The browser usually will re-fetch the main page when it changes and if you have changed the names of the CSS and javascript files, even by a single character, they will fetched because the new names will not be in the cache.
Top Expert 2013

Commented:
The solution Dave offers is a commonly used approach.  You can just add the version number to the new file.  The only drawback the approach has is if you are delivering static pages with the file names hard-coded; in which case you will need to change the file name on every page.

Cd&

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial