New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

cachebust

Package Overview
Dependencies
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

cachebust - npm Package Compare versions

Comparing version 1.1.0 to 2.0.0

73

lib/cachebust.js

@@ -12,54 +12,53 @@ /*

var $ = require('cheerio'),
var cheerio = require('cheerio'),
MD5 = require('MD5'),
fs = require('fs');
exports.busted = function(fileContents, options) {
var self = this;
function loadAttribute(content) {
if (content.name.toLowerCase() === 'link') {
return content.attribs.href;
}
options.basePath = options.basePath || "";
if (options.type === 'timestamp') {
self.timestamp = new Date().getTime();
if (content.name.toLowerCase() === 'script') {
return content.attribs.src;
}
var protocolRegEx = /^http(s)?/,
scripts = $(fileContents).find('script'),
styles = $(fileContents).find('link[rel=stylesheet]'),
data;
throw "No content awaited in this step of process";
}
// Loop the stylesheet hrefs
for (var i = 0; i < styles.length; i++) {
var origHref = styles[i].attribs.href,
styleHref = styles[i].attribs.href.split("?")[0];
// Test for http(s) and don't cache bust if (assumed) served from CDN
if (!protocolRegEx.test(styleHref)) {
if (options.type === 'timestamp') {
fileContents = fileContents.replace(origHref, styleHref + '?t=' + self.timestamp);
} else {
data = fs.readFileSync(options.basePath + styleHref).toString();
fileContents = fileContents.replace(origHref, styleHref + '?v=' + MD5(data));
}
}
}
exports.busted = function(fileContents, options) {
var self = this, $ = cheerio.load(fileContents);
// Loop the script srcs
for (var j = 0; j < scripts.length; j++) {
var origSrc = scripts[j].attribs.src,
scriptSrc = scripts[j].attribs.src.split("?")[0];
self.MD5 = function(fileContents, originalAttrValue, options) {
var originalAttrValueWithoutCacheBusting = originalAttrValue.split("?")[0],
hash = MD5(fs.readFileSync(options.basePath + originalAttrValueWithoutCacheBusting).toString());
return fileContents.replace(originalAttrValue, originalAttrValueWithoutCacheBusting + '?v=' + hash);
};
self.timestamp = function(fileContents, originalAttrValue, options) {
var originalAttrValueWithoutCacheBusting = originalAttrValue.split("?")[0];
return fileContents.replace(originalAttrValue, originalAttrValueWithoutCacheBusting + '?t=' + options.currentTimestamp);
};
options = {
basePath : options.basePath || "",
type : options.type || "MD5",
currentTimestamp : new Date().getTime()
};
var protocolRegEx = /^http(s)?/, elements = $('script[src], link[rel=stylesheet][href]');
for (var i = 0, len = elements.length; i < len; i++) {
var originalAttrValue = loadAttribute(elements[i]);
// Test for http(s) and don't cache bust if (assumed) served from CDN
if (!protocolRegEx.test(scriptSrc)) {
if (options.type === 'timestamp') {
fileContents = fileContents.replace(origSrc, scriptSrc + '?t=' + self.timestamp);
} else {
data = fs.readFileSync(options.basePath + scriptSrc).toString();
fileContents = fileContents.replace(origSrc, scriptSrc + '?v=' + MD5(data));
}
if (!protocolRegEx.test(originalAttrValue)) {
fileContents = self[options.type](fileContents, originalAttrValue, options);
}
}
return fileContents;
};
{
"name": "cachebust",
"version": "1.1.0",
"version": "2.0.0",
"main": "lib/cachebust.js",

@@ -27,4 +27,4 @@ "description": "Append a query string to your assets to bust that cache!",

"dependencies": {
"MD5": "^1.2.1",
"cheerio": "^0.17.0"
"md5": "^2.0.0",
"cheerio": "^0.19.0"
},

@@ -31,0 +31,0 @@ "devDependencies": {

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc