Solved

Cache clearing in php website

Posted on 2014-11-19
5
82 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Text in block not displaying properly 2 33
how to pick specific file from ftp 13 39
alert before form submission 6 30
Problem with a CSS in a page 2 26
Styling your websites can become very complex. Here I'll show how SASS can help you better organize, maintain and reuse your CSS code.
CSS is a visual language used to classify objects and define rules about how they should be displayed. CSS skills aren’t restricted to developers anymore, there is a big benefit to having a basic understanding of the language, regardless of your occ…
In this tutorial viewers will learn how to style elements, such a divs, with a "drop shadow" effect using the CSS box-shadow property Start with a normal styled element, such as a div.: In the element's style, type the box shadow property: "box-shad…
The viewer will learn how to count occurrences of each item in an array.

911 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

24 Experts available now in Live!

Get 1:1 Help Now