Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.

  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint
Share this Page URL
Help

8. WebWorker API > Hack 68. Use Import Scripts to Make Twitter JSONP Requests

Hack 68. Use Import Scripts to Make Twitter JSONP Requests

The WebWorker API allows you to import third-party or external libraries through the use of the importScripts() method. JSONP, or JSON with padding, is a widely used technique for fetching JavaScript from other domains without having to adhere to the browser’s same origin policy.

In this hack we will make a call to the Twitter Search API to obtain the last 100 tweets that contain the html5 keyword within their body. We will leverage the importScript() function available to us in the worker context.

As with any dedicated worker, the first thing we will do is to create a new Worker and point to an external file:

var worker = new Worker("javascripts/jsonp-worker.js");

  

You are currently reading a PREVIEW of this book.

                                                                                                                    

Get instant access to over $1 million worth of books and videos.

  

Start a Free Trial


  
  • Safari Books Online
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint