connect-cachify
Advanced tools
Comparing version 0.0.14 to 0.0.15
@@ -77,2 +77,4 @@ # connect-cachify API # | ||
* ``hash`` - MD5 hash to use instead of calculating from disk (**Default: none**) | ||
* ``defer`` - if true, adds the defer attribute to scripts in production mode. (**Default: false**) | ||
* ``async`` - if true, adds the async attribute to scripts in production mode. (**Default: false**) | ||
@@ -79,0 +81,0 @@ In production mode, a single script tag is generated, with a cache-busting |
@@ -208,5 +208,22 @@ /* This Source Code Form is subject to the terms of the Mozilla Public | ||
if (! options) options = {}; | ||
return prod_or_dev_tags(filename, | ||
'<script src="%s"></script>', | ||
options.hash); | ||
var link_fmt = '<script src="%s"' | ||
/** | ||
* indicate to a browser that the script is meant to be executed after the | ||
* document has been parsed. | ||
*/ | ||
if (options.defer && opts.production === true) { | ||
link_fmt += ' defer'; | ||
} | ||
/** | ||
* indicate that the browser should, if possible, execute the script | ||
* asynchronously | ||
*/ | ||
if (options.async && opts.production === true) { | ||
link_fmt += ' async'; | ||
} | ||
link_fmt += '></script>'; | ||
return prod_or_dev_tags(filename, link_fmt, options.hash); | ||
}; | ||
@@ -213,0 +230,0 @@ |
@@ -6,3 +6,3 @@ { | ||
"keywords": ["cache", "HTTP", "expires", "asset", "max-age", "caching"], | ||
"version": "0.0.14", | ||
"version": "0.0.15", | ||
"homepage": "http://github.com/mozilla/connect-cachify", | ||
@@ -9,0 +9,0 @@ "repository": { |
@@ -113,2 +113,15 @@ var cachify = require('../lib/connect-cachify'), | ||
"debug option puts hash in all urls"); | ||
links = cachify.cachify_js("/js/main.min.js", | ||
{ defer: true }).split('\n'); | ||
test.equal(links[0], | ||
'<script src="/d41d8cd98f/js/lib/jquery.js"></script>', | ||
"defer: true does not add defer attribute with production=false"); | ||
links = cachify.cachify_js("/js/main.min.js", | ||
{ async: true }).split('\n'); | ||
test.equal(links[0], | ||
'<script src="/d41d8cd98f/js/lib/jquery.js"></script>', | ||
"async: true does not async attribute with production=false"); | ||
files = cachify.cachify("/js/main.min.js", {tag_format: '<script src="%s" defer></script>'}).split('\n'); | ||
@@ -170,2 +183,15 @@ test.equal(files[0], '<script src="/d41d8cd98f/js/lib/jquery.js" defer></script>'); | ||
"Hashes in all urls in production"); | ||
links = cachify.cachify_js("/js/main.min.js", | ||
{ defer: true }).split('\n'); | ||
test.equal(links[0], | ||
'<script src="/d41d8cd98f/js/main.min.js" defer></script>', | ||
"defer: true adds defer attribute with production=true"); | ||
links = cachify.cachify_js("/js/main.min.js", | ||
{ async: true }).split('\n'); | ||
test.equal(links[0], | ||
'<script src="/d41d8cd98f/js/main.min.js" async></script>', | ||
"async: true adds async attribute with production=true"); | ||
var file = cachify.cachify("/js/main.min.js"); | ||
@@ -172,0 +198,0 @@ test.equal(file, "/d41d8cd98f/js/main.min.js"); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
53962
700