I've been working on a project to create a Shakespeare twitter-bot. While parsing all of Shakespeare's work from the MIT hosted web pages I used the jsdom package to crawl through the html. Recently while working on the project offline, I came into some problems with jsdom. The below sample from jsdom's github wouldn't work while I was offline:

// Count all of the links from the Node.js build page
var jsdom = require("jsdom");

jsdom.env(  
  "http://nodejs.org/dist/",
  ["http://code.jquery.com/jquery.js"],
  function (errors, window) {
    console.log("there have been", window.$("a").length, "nodejs releases!");
  }
);

In order to load jquery from a local source the devs for jsdom suggest using the following format for grabbing a local source files:

// Print all of the news items on Hacker News
var jsdom = require("jsdom");  
var fs = require("fs");  
var jquery = fs.readFileSync("./jquery.js", "utf-8");

jsdom.env({  
  url: "http://news.ycombinator.com/",
  src: [jquery],
  done: function (errors, window) {
    var $ = window.$;
    console.log("HN Links");
    $("td.title:not(:last) a").each(function () {
      console.log(" -", $(this).text());
    });
  }
});

I don't know what the reason was, but I couldn't get this to perform correctly. So instead I'm running a local python bottle server in order to serve myself the jquery file when offline:

from bottle import Bottle, run, static_file

app = Bottle()

@app.route('/static/<filename>')
def server_static(filename):  
    return static_file(filename, root='./static')

run(app, host='localhost', port=8080)

Now I update the original jsdom JavaScript, connect with the localhost on the Python Bottle server port, and everything is happiness:

// Count all of the links from the Node.js build page
var jsdom = require("jsdom");

jsdom.env(  
  "http://nodejs.org/dist/",
  ["http://localhost:8080/static/jquery.js"],
  function (errors, window) {
    console.log("there have been", window.$("a").length, "nodejs releases!");
  }
);