Welcome Guest, Not a member yet? Register   Sign In
Ideas on how to generate new CSS file name on changes to CSS content?
#1

[eluser]randomdriver[/eluser]
I cache my CSS files for a long time and therefore rename the CSS file each time there is an update. This way returning users get the latest file and speed of loading the site is fast.

The issue I have is each time I have to rename the file in my version control system and I also have to update the links to that file name.

Curious if anyone has a best practice for making it dynamic. In my controller I always call the necessary CSS files needed, then pass that to the views. So I'd like to continue doing that but have something update the name of the file on the file server, and match it in the html.

Make sense?
#2

[eluser]ecsyle31[/eluser]
Code:
<link rel="stylesheet" href="http://example.org/style.css?v=<?php echo $VERSION ?>" type="text/css" />

$VERSION can be a variable you define like your code version, revision date, anything. Your browser will see the url as new and re-cache the css.
#3

[eluser]Eric Barnes[/eluser]
You may want to research that as some browsers do don't treat it as a new file. I can't remember right off which one or ones but I know I have read it.
#4

[eluser]rogierb[/eluser]
If you are using cache (library) there must be a way to delete it. Why not build a module/controller/whatever that processes caching.
That's how I do it.

If your not using a cache library but browser caching, you could use a dynamic name like rlindauer said or use a different name (DEFINE or variable) like
Code:
<link rel="stylesheet" href="http://example.org/<?php echo CURRENT_CSS_NAME ?>" type="text/css" />




Theme © iAndrew 2016 - Forum software by © MyBB