Solved

Cache clearing in php website

Posted on 2014-11-19
5
83 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
ID: 40452221
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
ID: 40453359
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
ID: 40454390
Thank you Computer and Coboldinosaur.
Coboldinosaur
- then so what would be the best solution for this Coboldinosaur. Please let me know.

Thanks
0
 
LVL 83

Accepted Solution

by:
Dave Baldwin earned 500 total points
ID: 40454534
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
ID: 40455689
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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Introduction If you're like most people, you have occasionally made a typographical error when you're entering information into an online form.  And to your consternation, the browser remembers the error, and offers to autocomplete your future entr…
Styling your websites can become very complex. Here I'll show how SASS can help you better organize, maintain and reuse your CSS code.
In this tutorial viewers will learn how to style different bullet points for unordered lists in CSS. Begin with a normal unordered list; the default bullet point is a solid circle: In the CSS, create a defined class of unordered list by typing "ul.S…
The viewer will receive an overview of the basics of CSS showing inline styles. In the head tags set up your style tags: (CODE) Reference the nav tag and set your properties.: (CODE) Set the reference for the UL element and styles for it to ensu…

809 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