0

I want

<link rel="stylesheet" type="text/css" href="/css/site.min.v1.1.css" />
<script type="text/javascript" src="/js/site.min.v1.1.js"/>

same as

<link rel="stylesheet" type="text/css" href="/css/site.min.css" />
<script type="text/javascript" src="/js/site.min.js"/>

and it can use with /css/site.v1.1.css

but it dont work. Help me write htaccess .


i test with

RewriteRule ^(css|js)/(.+(?:min)?)\.(.+)\.(js|css)$ $1/$2.$4 [L]

it wor for 2 above example but dont work with /js/jquery-1.4.2.min.js


it work with RewriteRule ^(css|js)/(.*(?:min)?)(\.v.*)+\.(js|css)$ $1/$2.$4 [L]

2
  • What’s the syntax for that version information? Commented Nov 20, 2010 at 15:03
  • v1.1 is version information. or anything . but i want keep "site.min" Commented Nov 20, 2010 at 15:05

2 Answers 2

1

When expecting it to be necessary to do site wide changes, sometimes for simplicity, if php is available, I start off by including a simple php set in the appropriate part of all the html documents' <head>s

<?php  
 include "absolute_path/jQueryInclude.html"
?>

And then have the file jQueryInclude.html using the actual series number (1.1 in your example), so it appears true in the header if you review source of any document.

<link rel="stylesheet" type="text/css" href="/css/site.min.v1.1.css" />
<script type="text/javascript" src="/js/site.min.v1.1.js"/>

You only need to change jQueryInclude.html to change the header of all files that include it.

This can make it much easier to handle other site wide changes as well. And you can have different include statements for different groups of html page files. Perhaps a cleaner more understandable/and re-viewable way in the long term.

Its really similar to server side includes, just using your normal html extension for your main files and php instead.

Sign up to request clarification or add additional context in comments.

Comments

0

I highly doubt what you are doing is good practice at all, as it will probably bring you more headaches than benefit. You should be able to include /js/jsquery-1.4.2.min.js into your set by including another rewrite rule (after the one you already provider) along these lines:

RewriteRule ^(css|js)/([^-]+)(?:[0-9.-]+)(\.min\.)(js|css)$ $1/$2$3$4 [L]

but again this really looks like an ugly patch. It's very general, it's unreliable, it's hiding version information, it's going to cause you issues - don't do it.

Think about other ways to solve the problem. I don't understand what exactly is the root cause that made you try to remove the versions, but I suggest you take a look at that.

3 Comments

i read a articles, it say: "make sure the site visitor gets the new version when i update css, js". I 'll change css file 's name . But it is still same a file.
It may be OK to upgrade to new version, but you should not do it blindly - you should update it properly in your application, test it and release with a versioned file. Otherwise, you can unintentionally change the behaviour of application.
Like meotimdihia it is a good idea that you actually use some sort of version/serial number in the HTML to reference the CSS, JavaScript. But it all depends on the cache headers that you send with your resources. For instance if you had 1 month time out on your CSS files, that there would be no way for you to push new CSS to the client. If you on the other hand used version numbers in your file references, then the browser would always fetch the version you want - you are back in control.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.