
Product
A New Overview in our Dashboard
We redesigned Socket's first logged-in page to display rich and insightful visualizations about your repositories protected against supply chain threats.
appcache-node
Advanced tools
###Let their browsers do the work
This module auto-generates your HTML5 Application Cache manifest, making it very easy to implement. In Node.JS, but for any web server. This makes for massive decrease on your server load.
###Installation
$ npm install appcache-node
Any HTML page with this will cache
<html manifest="app.cache">
In your app
var c = require('appcache-node');
// generate a cache file
var cf = c.newCache();
// in your request handler
if(r.url.match(/app\.cache$/)){
s.writeHead(200, {'Content-Type': 'text/cache-manifest'});
return s.end(cf);
}
While your HTML page caches automatically, you specify any JS, CSS, IMG, etc.. your page uses, so you have full control over which files are included in the cache.
var c = require('appcache-node')([
'http://netdna.bootstrapcdn.com/twitter-bootstrap/2.2.2/css/bootstrap-combined.min.css'
, 'http://netdna.bootstrapcdn.com/twitter-bootstrap/2.2.2/js/bootstrap.min.js'
]);
When you restart your app, the app.cache is rebuilt and so cache is cleared.
or here's a trick to have the cache reset every hour, if you want browsers to have to reload periodically.
// generate a cache file
var cf = c.newCache([
'http://netdna.bootstrapcdn.com/twitter-bootstrap/2.2.2/css/bootstrap-combined.min.css'
, 'http://netdna.bootstrapcdn.com/twitter-bootstrap/2.2.2/js/bootstrap.min.js'
]);
// optional - invalidate and reload the cache every 1 hour
setInterval(function(){
cf = c.newCache([
'http://netdna.bootstrapcdn.com/twitter-bootstrap/2.2.2/css/bootstrap-combined.min.css'
, 'http://netdna.bootstrapcdn.com/twitter-bootstrap/2.2.2/js/bootstrap.min.js'
])
}, 1000*60*60);
###toDataURI(filename) A helper function is included, to convert images to data-uris, thereby embedding them into the HTML page, although this is not required to use the appcache.
var c = require('./appcache.js');
var duri = '<img src="' + c.toDataURI('./epic.png') + '"/>';
==> "<img src='data:image/png;base64,iVBORw0KGgo...'/>"
###Test Run test.js to run an example web server.
More about the HTML5 Application Cache:
http://www.w3schools.com/html/html5_app_cache.asp
FAQs
appcache-node =============
The npm package appcache-node receives a total of 8 weekly downloads. As such, appcache-node popularity was classified as not popular.
We found that appcache-node demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
We redesigned Socket's first logged-in page to display rich and insightful visualizations about your repositories protected against supply chain threats.
Product
Automatically fix and test dependency updates with socket fix—a new CLI tool that turns CVE alerts into safe, automated upgrades.
Security News
CISA denies CVE funding issues amid backlash over a new CVE foundation formed by board members, raising concerns about transparency and program governance.