Solved

Cache clearing in php website

Posted on 2014-11-19
5
79 Views
Last Modified: 2014-11-20
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.
0
Comment
Question by:karthik80c
5 Comments
 
LVL 35

Expert Comment

by:Kimputer
Comment Utility
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');
0
 
LVL 53

Expert Comment

by:COBOLdinosaur
Comment Utility
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&
0
 

Author Comment

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

Thanks
0
 
LVL 82

Accepted Solution

by:
Dave Baldwin earned 500 total points
Comment Utility
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.
0
 
LVL 53

Expert Comment

by:COBOLdinosaur
Comment Utility
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&
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Column Spacing 3 33
Adding a menu section 13 34
Menu Inconsistent 3 19
Need a good Angular tutorial 5 22
Building a website can seem like a daunting task to the uninitiated but it really only requires knowledge of two basic languages: HTML and CSS.
This article discusses four methods for overlaying images in a container on a web page
The viewer will learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now