Welcome to webassets-iife’s documentation!¶
webassets-iife is a webassets filter to wrap a JavaScript bundle in an IIFE to prevent global leaks and improve minification.
Installation¶
Install webassets-iife with pip:
[sudo] pip install webassets-iife
It supports both Python 2.x and 3.x.
Usage¶
With Flask¶
This will concat myscript1.js and myscript2.js into one JS chunk, wrap it in an IIFE and minify it.
IIFE?¶
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.
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.