IIFE filter for webassets
Project description
webassets-iife is a webassets filter to wrap a JavaScript bundle in an IIFE to prevent global leaks and improve minification.
Install
pip install webassets-iife
Usage
For example with Flask:
from flask.ext.assets import Environment, Bundle
from webassets_iife import IIFE
# ...
assets = Environment(app)
js = Bundle('myscript1.js',
'myscript2.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.
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.
// 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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
File details
Details for the file webassets-iife-0.1.0.tar.gz
.
File metadata
- Download URL: webassets-iife-0.1.0.tar.gz
- Upload date:
- Size: 3.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | ac9769ecb303e4b2364b2b1da3a300d1118012dc8faeb54f9f6a63b3029e2771 |
|
MD5 | c6e86447e76df42e201af31f05b4c198 |
|
BLAKE2b-256 | d78a4da381a1c8dc81d0a23751d6e72cbc47dbee8745fba465717404dd5a6ae9 |