Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

externalize

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

externalize - npm Package Compare versions

Comparing version 0.1.0 to 0.1.1

LICENSE

2

index.js

@@ -133,3 +133,3 @@

module.exports = function(parents, externals, cb) {
module.exports = function externalize(parents, externals, cb) {
cb = once(cb);

@@ -136,0 +136,0 @@ parents = [].concat(parents);

{
"name": "externalize",
"version": "0.1.0",
"version": "0.1.1",
"description": "Create external Browserify bundles for lazy asynchronous loading",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -7,2 +7,6 @@ [![build status](https://secure.travis-ci.org/epeli/browserify-externalize.png)](http://travis-ci.org/epeli/browserify-externalize)

Introduction to asynchronous module loading with Browserify:
<http://esa-matti.suuronen.org/blog/2013/04/15/asynchronous-module-loading-with-browserify/>
## Install

@@ -45,3 +49,3 @@

// Make subset bundle from external.js by making it explicitly requireable
var second = browserify().require("./external.js");
var subset = browserify().require("./external.js");

@@ -53,16 +57,16 @@ // Remove the subset bundle code from the parent

// Write bundles to files after externalization
parent.bundle.pipe(fs.createWriteStream("bundle/parent.js");
second.bundle.pipe(fs.createWriteStream("bundle/second.js");
parent.bundle().pipe(fs.createWriteStream("bundle/parent.js"));
subset.bundle().pipe(fs.createWriteStream("bundle/subset.js"));
});
```
index.js
index.js:
```javascript
// would not work here because external.js is externalized to the subset bundle
// require("./external");
// Would not work here because external.js is externalized to the subset bundle
// Use any script loader to load the subset bundle to make the require work
// again
jQuery.getScript("bundle/second.js", function(){
jQuery.getScript("bundle/subset.js", function(){
var value = require("./external");

@@ -80,2 +84,22 @@ // Alerts: "external module: external module contents"

## Script loaders
You need a script loader to load the external bundles. There is one in
[jQuery][getscript]. If you don't use jQuery you can grab [$script.js][]
from [npm][$script.js-npm] or implement your [own][modern] for modern browsers
easily.
Some others include:
- [yepnope](http://yepnopejs.com/)
- [head.js](http://headjs.com/)
- [lab.js](http://labjs.com/)
- [lazyload](https://github.com/rgrove/lazyload/)
- [basket.js](http://addyosmani.github.io/basket.js/)
[Browserify]: https://github.com/substack/node-browserify
[getscript]: http://api.jquery.com/jQuery.getScript/
[$script.js]: http://dustindiaz.com/scriptjs
[$script.js-npm]: https://npmjs.org/package/scriptjs
[modern]: https://gist.github.com/epeli/5384178
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc