Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

autostatic

Package Overview
Dependencies
Maintainers
1
Versions
17
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

autostatic

Automatically serve static files, with version control (etag support), compression and CDN support. This makes it possible to skip all the annoying packaging process when deploying your application.

  • 0.1.1-2
  • latest
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

AutoStatic

Automatically serve static files, with version control (etag supported), compression and CDN support. This makes it possible to skip all the annoying packaging process when deploying your application.

You may also want to try a inline static management module.

Usage

var express = require('express');
var autostatic = require('autostatic');

var app = express();

var as = autostatic({
  root: 'http://img.example.com',
  dir: __dirname + '/public'
});

app.use(as.middleware());
app.use(express.static(__dirname + '/public'));

app.locals({
  static: as.helper(),
});

In template:

<script src="${static('/js/abcd.js')}"></script>

this will output as:

<script src="http://img.example.com/js/abcd.min.js?1234567-8900"></script>

The abcd.min.js file is generated by this module automatically. This is an asynchronous process, so it will serve the original /js/abcd.js first, and cache control is handled by express.static middleware. Once the minified version of this file is ready, minified file with etag as suffix (/js/abcd.min.js?122456-123) will be served.

You can set up a unique domain for your assets (img.example.com), in Nginx or Apache, with your public files directory as root (in Nginx) or DocumentRoot (in Apache).

Or, set up an upload method to deploy the compressed file to CDN:

var as = autostatic({
  root: 'http://img1.xxcdn.com',
  upload: function(path, contents) {
    // your upload method
  }
});

Concatenating files

You can use autostatic to serve multiple static files.

<script src="${static('/js/abcd.js', '/js/efgh.js')}"></script>

will output:

<script src="/autostatic??/js/abcd.js,/js/efgh.js"></script>

The path /autostatic can be configured:

autostatic.set({
  route: '/serve_assets'
});

Keywords

FAQs

Package last updated on 27 Apr 2013

Did you know?

Socket

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.

Install

Related posts

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