在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称(OpenSource Name):UltCombo/gulp-buster开源软件地址(OpenSource Url):https://github.com/UltCombo/gulp-buster开源编程语言(OpenSource Language):JavaScript 100.0%开源软件介绍(OpenSource Introduction):gulp-busterCache buster hashes generator for gulp. Blazing fast and fully configurable. What is cache busting?It is basically a way to expire a given resource. As a mean to optimize web applications, it is recommended to set assets' expiration date to a long time in the future (usually one month to one year). This way, the browser can load the cached resources from the local disk rather than over the network. But of course, that also means the browser won't even attempt to load a resource from the network while it has a non-expired cached version of the given resource, even if that resource has been modified in the server. Then, how to invalidate this cached resource and force the browser to load the new version? Here enters cache busting, also known as "fingerprinting", as described in Optimize Caching - Google Developers:
Note: Even if you are not explicitly setting expiration headers, browsers are allowed to and will cache assets such as CSS and image files. This means, without proper cache busting, your clients may get broken pages (e.g. updated markup with outdated styling and images which were automatically cached by the browser) even if your server does not send caching headers! (which it should send anyway) Of course, technically, the caching issue could be worked around if every client refreshes the page, but that is not obvious to every user and, obviously, it would provide a terrible user experience and negatively affect the overall image of your product. And you don't want that, right? InstallFirst off, install gulp. Then install gulp-buster as a development dependency:
How to usegulp-buster can be used standalone as part of a build task, or in conjunction with gulp-watch to update the cache buster hashes as the files are modified. Example with gulp-watch var gulp = require('gulp'),
watch = require('gulp-watch'),
sass = require('gulp-ruby-sass'),
bust = require('gulp-buster');
gulp.task('default', function() {
var srcGlob = 'scss/*.scss';
return gulp.src(srcGlob)
.pipe(watch(srcGlob, function(files) {
return files
.pipe(sass())
.pipe(gulp.dest('css'))
.pipe(bust()) // pipe generated files into gulp-buster
.pipe(gulp.dest('.')); // output busters.json to project root
}));
}); Syntax
Parameters
Note: all of the options which accept a function can be run asynchronously by returning a promise (or thenable). If the given option has a return value constraint, the constraint will still be applied to the promise's fulfillment value. Integrating with Web applicationsgulp-buster is language-agnostic, thus this part relies on you and your specific use case. By default, gulp-buster generates a JSON file in the following format: {
"path/to/file/relative/to/project/root/filename.ext": "hash",
//other entries
} Integration can be easily achieved on any language which supports JSON parsing, in either back-end or front-end. See the Implementations page for examples and existing solutions for your language of choice. Note: The output file contents' data structure and format can be customized through the configuration options. This enables gulp-buster to output the cache buster hashes file in a suitable native data structure for your target language, as well as allowing to mutate the paths and hashes to suit your specific needs. ArchitectureWhen gulp-buster is initialized, it creates an empty object which serves as a cache for the generated hashes. Generated hashes are then grouped by the
There are close to no cons, the only notable drawback is that all the to-be-busted files must be piped into gulp-buster (preferably at startup) before it generates the output file with all hashes that you'd expect. A feature to allow inputting an already-generated hashes file was considered in order to avoid having to pipe all the to-be-busted files at startup, but that seems to bring more cons than pros -- the auto-cleanup of deleted files' hashes would no longer happen, outdated hashes could stay in the output hashes file if the to-be-busted files were edited while gulp was not running, and finally it'd also be incompatible with the ChangelogFAQQ. Is the correct name Gulp-Buster, gulp-buster or Gulp-buster? |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论