Skip to main content

IIFE filter for webassets

Project description

Build status Coverage status Pypi package

webassets-iife is a webassets filter to wrap a JavaScript bundle in an IIFE to prevent global leaks and improve minification.


pip install webassets-iife


For example with Flask:

from flask.ext.assets import Environment, Bundle
from webassets_iife import IIFE

# ...

assets = Environment(app)

js = Bundle('myscript1.js',
            filters=(IIFE, 'closure_js'), output='all.min.js')
assets.register('js_all', js)

This will concat myscript1.js and myscript2.js into one JS chunk, wrap it in an IIFE and minify it.


An IIFE is an Immediately-Invoked Function Expression. It’s an anonymous function that’s declared and invoked immediately after that. It’s used in JavaScript to create a closed environment which can’t be accessed from the outside.

// a and b can be accessed by external code
var a = 3,
    b = 1;
// ... some code ...

// a and b can't be accessed by external code
(function() {
    var a = 3,
        b = 1;
    // ... some code ...

Wrapping code in an IIFE helps the minifier see the dead code, because it knows that these local variables can’t be accessed from the outside and thus can remove them or mangled their name.

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for webassets-iife, version 0.1.0
Filename, size File type Python version Upload date Hashes
Filename, size webassets-iife-0.1.0.tar.gz (3.3 kB) File type Source Python version None Upload date Hashes View

Supported by

Pingdom Pingdom Monitoring Google Google Object Storage and Download Analytics Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page