Skip to main content

webassets-iife

Build status Coverage status Pypi package https://img.shields.io/pypi/dm/webassets-iife.png

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.

Metadata

Release files for webassets-iife 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for webassets-iife 0.1.0
File Size Uploaded
webassets-iife-0.1.0.tar.gz 3.3 kB Details

Release files / webassets-iife-0.1.0.tar.gz

Download URL webassets-iife-0.1.0.tar.gz
Size 3.3 kB
Tags Source
SHA-256 checksum
How to use checksums
ac9769ecb303e4b2364b2b1da3a300d1118012dc8faeb54f9f6a63b3029e2771
BLAKE2b-256 checksum
How to use checksums
d78a4da381a1c8dc81d0a23751d6e72cbc47dbee8745fba465717404dd5a6ae9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release history Release notifications | RSS feed

This release

0.1.0 This release

1 release file

0.0.2

1 release file

0.0.1

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page