npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

gulp-rev-append-plus

v0.1.11

Published

Cache-busting plugin for gulp.

Downloads

2

Readme

gulp-rev-append-plus

gulp plugin for cache-busting files using query string file hash, it is base on gulp-rev-append

installation

$ npm install gulp-rev-append-plus --save-dev

how?

gulpfile.js

var rev = require('gulp-rev-append-plus');

var reg= /(?:href=|src=|poster=|url\()(?:['|"]?)([^\s>']+?)\?v=(@@).+(?:['|"|>]?)/gi;
var md5_len = 20;

gulp.task('rev', function() {
  gulp.src('./index.html')
    .pipe(rev(reg,md5_len))
    .pipe(gulp.dest('.'));
});

terminal

$ gulp rev

what?

The gulp-rev-append-plus plugins allows for appending a query-string file hash to dependencies declared in html files defined using the following regex: /(?:href=|src=|poster=|url\()(?:['|"]?)([^\s>']+?)\?v=(@@).+(?:['|"|>]?)/gi;

That's fancy talk for any stylesheet or script declarations that are declared in an html file such as the following:

<!doctype html>
<html>
  <head>
    <link rel="stylesheet" type="text/css" href="style/style-one.css?v=@@">
    <script src="script/script-one.js?v=@@"></script>
    <script src="script/script-two.js"></script>
  </head>
  <body>
    <div><p>hello, world!</p></div>
    <script src="script/script-three.js?v=@@"></script>
  </body>
</html>

will turn into something similar as the following after running gulp-rev-append-plus:

<!doctype html>
<html>
  <head>
    <link rel="stylesheet" type="text/css" href="style/style-one.css?v=d65aaba987e9c1eefeb4be9cfd34e0de">
    <script src="script/script-one.js?v=17a5da6c8a2d875cf48aefb722eefa07"></script>
    <script src="script/script-two.js"></script>
  </head>
  <body>
    <div><p>hello, world!</p></div>
    <script src="script/script-three.js?v=5cadf43edba6a97980d42331f9fffd17"></script>
  </body>
</html>

also can work in css:


.a {
    background-image: url(../img/aa.png?v=@@);
}
.b {
    background-image: url('../img/aa.png?v=@@');
}
.c {
    background-image: url("../img/aa.png?v=@@");
}

Any subsequent runs of the gulp-rev-append-plus file will change the output only if the target file(s) declared have been modified. This is because the revision hash is computed using the target file contents.

why?

I wanted to easily define dependencies that require simple cache-busting by using a query-string hash. The hash is based on file content, so any modification to the file dependency would result in a change to the generated and appended hash - effectively cache-busting the dependency in simple scenarios.

Be Warned: Using query strings to cache-bust dependencies isn't fool proof.

Google | Leverage Proxy Cache Article
Steve Souders | Revving Filenames: don't use querystring

Other plugins that may work for your situation:

There are several gulp plugins that already support revisioning and cache-busting: https://www.npmjs.org/search?q=gulp-rev

I created this plugin as it fit my needs more clearly in:

  • enabling cache-busting by appending a file hash on query string
  • not requiring additionally markup commenting to declare dependencies to be modified
  • not generating an additional manifest to be a dependency in file access for production-level application

For its particular use, I am not concerned with firewalls or proxy cache; I was trying to develop a simple web-based mobile site on a desktop while testing on devices and cache-ing was giving me a headache. I did not want to modify my workflow and build to accommodate an addition cache-manifest, nor did I foresee my work being in production in which I needed to support a more robust cache-busting technique.

If the intent of this plugin does not meet your needs, please checkout the other possible solutions made by some awesome developers.

Tests

$ npm run test

License

Copyright (c) 2014 Todd Anderson

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.