npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

express-istatic

v0.1.0

Published

Add compressed inline css and scripts to your html, but write them as seperated files.

Readme

Inline Static Files for express / connect / nodejs

Why this?

Add compressed inline css and scripts to your html, but write them as seperated files.

You don't have to worry about accessing the template's local variables. And you can even include a .less file.

You may also like to have a loot at autostatic.

Usage:

var istatic = require('express-istatic');
va app = express.createServer();

app.locals({
  istatic: istatic.serve({ compress: false })
});

The parameter passed to istatic.serve is an options object, which is optional.

Available options are:

For css and js options, you can define an js.filter or css.filter, to do some filtering(like remove console.log()) before compressing.

eg.

{
  js: {
    filter: function(str) {
      return str.replace(/console.log(.+?)/, '');
    }
  }
}

In template:

Now you can include static files in your template like this:

#{istatic(filename, [options])}

filename is the path of your static file. If it begins with a '/', the real path will be process.cwd() + filename. Otherwise, the file will be looked up from the root of your inline static files, as you configured before.

You can set available options above, except for root and ttl. A fresh option is available for you to set this istatic call always read from file directly.

Be careful, since jade can not correctly parse curly braces inside a couple of curly braces, don't write:

script
  #{istatic('js/my.js', { showPath: (DEBUG ? true : false) })}

Write like this instead:

istatic_opt = { showPath: (DEBUG ? true : false) }
script
  #{istatic('js/my.js', istatic_opt)}

And it's definitely easier to read and maintain, too.

Templates' Local Variables:

Just get in touch with them in the form you already very familiar with:

#{data.title}

Attention: no matter what templating language you are using, you must always use this syntax in your static files. And don't put {} inside the curly braces. This is for performance consideration.

You can even excecute a local funtion just as what you will do in the template:

#{usr.getId('haha...')}

API

NOTE: These APIs are not for templates.

istatic(filename, [options])

Return the inlined string of some file.

Everytime you call istatic directly, it the options is given, these options will be saved as default options for any other later istatic or istatic.serve calls.

But when you call istatic(filename, options) from a template, the options will not be saved as default options.

APIs listed below are not suitable for an inside template call.

istatic.serve([options])

To return a function of istatic(filename, [options]), to read the file. This is typically used as an express helper.

istatic.default(options)

Specificly set default options for istatic('filepath'), which will be set implicitly at the first call of istatic('filename', options) or istatic.serve(options).

istatic.uglify.css(str, [options])

Uglify some css string. Options are passed to UglifyCSS.

istatic.uglify.js(str, [options])

Uglify some js string. Options are passed to UglifyJS.

Example

In /app.js:

var express = require('express');
var istatic = require('express-istatic');

var app1 = express.createServer();
var app2 = express.createServer();

app1.locals({
  istatic: istatic.serve()
});
app2.locals({
  istatic: istatic.serve({ compress: false })
});

var compressed_css = istatic.uglify.css('.class1 { font: Arial; }');
var compressed_js = istatic.uglify.js('// some javascript codes..');

// will be compressed
var str_pinyin_js = istatic('/utils/pinyin.js');

app1.get('/example', function(req, res, next) {
  res.render('example.jade', {
    user: req.user
  });
});

In /view/example.jade:

script
  !{istatic('js/log_user.js')}

In /public/js/log_user.js:

var user = "#{user}"
user && $.post('/log', { user: user });

Licence

(The MIT License)

Copyright (c) 2012 Jesse Yang <[email protected]>

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.