Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

What method can add a version number at the back of the file? #131

Closed
rayliao opened this issue Aug 29, 2015 · 8 comments
Closed

What method can add a version number at the back of the file? #131

rayliao opened this issue Aug 29, 2015 · 8 comments
Labels

Comments

@rayliao
Copy link

rayliao commented Aug 29, 2015

<html>
<head>
    <!-- build:css css/combined.css -->
    <link href="css/one.css" rel="stylesheet">
    <link href="css/two.css" rel="stylesheet">
    <!-- endbuild -->
</head>
<body>
    <!-- build:js scripts/combined.js -->
    <script type="text/javascript" src="scripts/one.js"></script>
    <script type="text/javascript" src="scripts/two.js"></script>
    <!-- endbuild -->
</body>
</html>

I want the resulting HTML like this:

<html>
<head>
    <link rel="stylesheet" href="css/combined.css?v=20150829"/>
</head>
<body>
    <script src="scripts/combined.js?v=20150829"></script>
</body>
</html>
@jonkemp
Copy link
Owner

jonkemp commented Aug 30, 2015

Here's one way to do it.

https://github.com/yeoman/generator-gulp-webapp/blob/master/docs/recipes/asset-revisioning.md

@rayliao
Copy link
Author

rayliao commented Aug 31, 2015

gulp-rev appends content hashes like this:

unicorn.css → unicorn-d41d8cd98f.css

It change the name of the file, but I can't think of change the file name, is just add the version number:
unicorn.css → unicorn.css?v=d41d8cd98f

@manuel-di-iorio
Copy link

If you do this with useref, the version hash will be useless, because it will be changed only when you change the file, losing the "no-cache stuff"

One way to do this is to correctly handle the cache headers with the server but sometimes it's not possible, so you could do it yourself.
Example with php: echo "unicorn.css?v=" . strval(microtime(true));

Probably there is an automatic lib that can handle that for you

@philBrown
Copy link

@jonkemp

Here's one way to do it.

That obviously doesn't work with gulp-useref v3. Got any other suggestions?

@jonkemp
Copy link
Owner

jonkemp commented Dec 30, 2015

I submitted a pull request to update that doc last night and it's been merged. I tested that myself and it works. ✋

@philBrown
Copy link

@jonkemp thank you very much, that was definitely helpful.

@OXOYO
Copy link

OXOYO commented Jan 12, 2016

@jonkemp It`s work. Thanks.

@henriquechehad
Copy link

Some update about doing:

unicorn.css → unicorn.css?v=d41d8cd98f
instead:
unicorn.css → unicorn-d41d8cd98f.css
?

@rayliao rayliao closed this as completed May 31, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

6 participants