Mobile app version of vmapp.org
Login or Join
Rivera981

: Apache: How can I force the browser to reload CSS files? 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

@Rivera981

Posted in: #Apache #Cache

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.

10.02% popularity Vote Up Vote Down


Login to follow query

More posts by @Rivera981

2 Comments

Sorted by latest first Latest Oldest Best

 

@Margaret670

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.

10% popularity Vote Up Vote Down


 

@Jessie594

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.

10% popularity Vote Up Vote Down


Back to top | Use Dark Theme