Git Product home page Git Product logo

concatenate.js's Introduction

concatenate.js

Implements a technique to bundle large numbers of JS files into a single file while maintaining the original file boundaries and names inside development tools. Use this to make your JavaScript serving system be awesome during development without the complexity of source maps.

The module provides a single function to concatenate a list of JavaScript files into a single output stream in a way that, when executed in the browser, maintains the illusion in JS development tools, that the files had been loaded as individual script tags.

Chrome Dev Tools screen shot

When would you use it

  • When you have too many JS files to make loading via script tags feasible (because the HTTP requests take too long) during development.
  • As a component of a script loader to deliver slightly modified JS files in a single response while maintaining the original files. (i.e. to serve CommonJS files to the browser.)
  • ONLY FOR DEVELOPMENT, DO NOT USE THIS IN PRODUCTION!

Usage

var js = require('./concatenate')([
  {
    content: 'function foo() {alert("foo")}',
    filename: 'js/foo.js'
  },
  {
    content: 'function bar() {alert("bar")}',
    filename: 'js/bar.js',
    hostname: 'app2'
  }
]);

Specifying the hostname is optional, the default is 'app'. Chrome Dev Tools groups JS files under the hostname.

How does it work

This is using multiple eval calls with @sourceURL annotations in a single output stream.

How about source maps

This is better than source maps under these circumstances:

  • Your input language is JS
  • You are not working with obfuscated JS

Why is it better:

  • This is the real deal. The browser acts like there were real files. No leaky abstractions.
  • Also: This is just super simple, no special parsing or anything like that required at any point in the process.

Limitations

When you have a syntax error at least V8 based browsers will not show you a line number.

Browser support

(For the generated JS)

  • Chrome Dev Tools
  • Safari Dev Tools
  • Firebug (Not recommended. It gets really slow with large numbers of files)

Advanced Usage

The exported function supports a second param which is a function that gets to modify the output after the eval was added. You may find this useful for i.e. adding CommonJS module wrappers. For an example see example_common_js_simulator.js.

Fine print

Author
Malte Ubl (Google Inc.)
Copyright
Copyright © 2013 Google, Inc.
License
Apache 2.0

concatenate.js's People

Contributors

cramforce avatar heff avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

concatenate.js's Issues

screenshot in readme

I think it'd help a lot to have a screenshot in the readme that helps illustrate the before/after transformation

npm publish?

would be great if this was in npm.

fyi, there is already a module named concatenate.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.