swig-minifier

0.4.4-b • Public • Published



What it does

Minifies and caches html output generated by swig (coded to work with express framework, but could be used without)
You have the option to choose file cache, memory cache or redis.
File cache will be located in os.tmpdir() in a folder named 'swig-minifier'


Changelog

https://github.com/michaeldegroot/swig-minifier/commits/master


Getting Started

1. Start by installing the package:
npm install swig-minifier
2. Do awesome stuff
var swigMinifier = require('swig-minifier');

// Change your app.engine to set to render with swig-minifier
app.engine('html', swigMinifier.engine);

Your html code will now be automatically minified and cached via file, If you want more options over the module checkout the API below!


API

.init(Object)

{
    cacheFolder:    String  // Full path to a folder where to store cache (optional)
    cacheType:      String  // file, redis, memory, none
    hashGen:        String  // md5, sha512, sha256
}

Call this before using the .engine function and you can setup some options for swig-minifier. If you do not call init, default settings will be used:

cacheFolder:    os.tmpdir() + "/swig-minfier/"
cacheType:      "file"
hashGen:        "sha256"

Example for setting to cache to redis and generate the hash for the cache key via sha512

var swigMinifier = require('swig-minifier');

swigMinifier.init({
    cacheType:"redis",
    hashGen:"sha512"
});

Example for setting to cache to file system, and generate the hash for the cache key via md5

var swigMinifier = require('swig-minifier');

swigMinifier.init({
    cacheType:"file",
    hashGen:"md5"
});

.engine

Use this to replace your app.engine setting

Example

var express = require('express');
var app = require('express')();
var swigMinifier = require('swig-minifier');

app.engine('html', swigMinifier.engine);

.clearCache()

Will clear all cache

WARNING REDIS USERS: this issues a flushAll command!

Example

var swigMinifier = require('swig-minifier');

swigMinifier.clearCache();

Contact

You can contact me at specamps@gmail.com

Package Sidebar

Install

npm i swig-minifier

Weekly Downloads

5

Version

0.4.4-b

License

MIT

Last publish

Collaborators

  • ha5efgcmz94gy5rgx42uzqmp