Take the 2-minute tour ×
Webmasters Stack Exchange is a question and answer site for pro webmasters. It's 100% free, no registration required.

How to force the user's web browser to reload CSS files with Apache Server?

I updated my website's CSS file but some users are still seeing problems that would be resolved if their browsers fetched the latest versions.

share|improve this question
add comment

2 Answers

This would be for wordpress but you can use some of the php functions to do the same on your server

One way to solve this is to “version” your CSS file, by adding ?v=123 to the URL in the to your stylesheet.

<link rel="stylesheet" href="<?php bloginfo('stylesheet_url'); echo '?' . filemtime( get_stylesheet_directory() . '/style.css'); ?>" type="text/css" media="screen, projection" />

This automatically updates the ?12345678 ending part every time you modify the file. Now everyone instantly sees your changes.

share|improve this answer
add comment

In Apache you can control the user's browser cache by adding the following code to an .htaccess file. This file should be in the root of the website or in the folders you want to modify the default

<IfModule mod_mime.c>
    AddType text/css .css
</IfModule>

<IfModule mod_expires.c>
    ExpiresByType text/css                  "access plus 1 hour"
</IfModule>

Please note that in some Apache servers .htaccess may not work, or the server may not have the required modules.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.