Giter Club home page Giter Club logo

requirejs-web-workers's Introduction

#Using Web Workers with RequireJS

This is a simple plugin that allows you to declare a dependency on a web worker script using requireJS with a simple syntax. See here for primer on Web Workers.

    define(["worker!my-web-worker"], function(worker) {
		worker.onmessage = function (event) {
			alert("I got me a message!");
		};
	});

The plugin will return an initilized Worker object which will resolve the given module ID with the currently configured requireJS configuration (no need to hardcode script paths just for web workers).

If Worker is not defined (IE < 10), the plugin will load a fake Worker implementation so that your scripts can utilize the same Worker API whether the browser supports it or not.

##Install with Bower

bower install requirejs-web-workers

Then add src/worker.js and src/worker-fake.js to your project.

##How to Run Example Page

The example page just loops and counts to a very large number on a background thread. In order to run the example, you will need to run index.html from a server (e.g. localhost) rather than the file:// protocol for web workers to work.

To run the example with a lightweight node server, first install dependencies:

npm install

Make sure you have grunt-cli installed if you don't already have it:

npm install grunt-cli -g

Then, run the server and load the example page:

npm start

This will spin up a server at localhost:1337 and open your web browser.

requirejs-web-workers's People

Contributors

chadly avatar

Watchers

James Cloos avatar Wong Lok avatar  avatar

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.