How to make stylesheet refresh automatically
How to make stylesheet refresh automatically
Categories:When I build a site, I always make changes to the style.css file. I always add, modify or remove styles, but there was a problem. When someone came to see my site they would see an old version of the site because their browser would cache the style.css file. In order to avoid this, I came up with this drupal recipe or theme snippet.
Create a new stylesheet file in your theme's folder. Call it "uptodate.css".
Add a new block and put the code below inside. Select "php code" as input format.
<?php
drupal_add_css(path_to_theme()."/uptodate.css?".time(), $type = 'theme', $media = 'all', $preprocess = TRUE)
?>Enable the block.
Now you can add styles to "uptodate.css" file and they will take effect automatically. This is a great way to overwrite styles and to make sure all your visitors will see the latest version of your site's layout.
- 485 reads
This solution will force
This solution will force browsers to load the style sheet on every request, regardless of whether it has changed or not.
A better solution is to just increment a version number as part of the filename and have the html point to the newer version. This will force the style to be downloaded once, but then cached in browsers, proxy servers etc. from then on.
Yes you are right, I use
Yes you are right, I use this only in development phase. I guess its better to use your solution when the website is more stable.
Post new comment