Skip to content

gitgrimbo/resource-prefetch-tests

Repository files navigation

resource-prefetch-tests

Runs a series of tests to discover which approaches to prefetching resources work in a browser.

Install

git clone https://github.com/gitgrimbo/resource-prefetch-tests.git

Usage

First, start the server.

node server

Second, point your browser at http://localhost:3002.

Third, click the Start button. The tests will run, and the results will be displayed in the browser (as each individual test completes) and saved to disk (when all the tests are complete, to the ./_sessions folder).

Results

What do the results look like?

Or clone the repo and take a look at ./samples/results.html.

Also see ./samples/session.json.

Why?

By prefetching resources we hope to speed up subsequent user interactions with our site.

If we can prefetch required resources into the browser's cache before they are needed, then fetching those resources when they are needed should be much faster, as the browser has them in its cache.

The Tests

The tests are built up from combining the following dimensions:

  • prefetch approach
  • resource type
  • resource size
  • same-domain resource/cross-domain resource
  • CORS HTTP headers/no CORS HTTP headers

Prefetch approaches tested

These are the implementations of prefetch that are tested.

Resource types tested

These are the resource types that are tested. Some prefetch implementations work for some resources types but not others.

  • JPG
  • JS
  • CSS
  • WOFF

Resource sizes tested

There are 'large', 'medium' and 'small' versions of JPG, CSS and JS.

The test server also deliberately throttles the bandwidth available to the test resources. This is because some browsers reject (do not download and/or do not cache) resources once they realise the resource is not the expected content type. E.g. Firefox 49 and IE 11 will reject (not cache) non-image resources prefetched using the new Image().src = url approach, but Chrome 53 caches these resources successfully.

Having large, medium and small resources, plus the bandwidth throttling, facilitates exposing this browser behaviour.

CORS and non-CORS

Each resource+approach combination is also tested with CORS and non-CORS requests.

A request with the useCors=true query parameter will instruct the test server to add the CORS HTTP response headers.

Known browser behaviour

IE11

IE9

  • XHR differences can be seen based on IE security zones. E.g. out-of-the-box IE9 may have "Access data sources across domains" disabled, but this setting may be enabled in Sauce Labs. This can be the difference between the XHR prefetch results passing or failing. See https://www.webdavsystem.com/ajax/programming/cross_origin_requests.

Edge

Client JS Build

Uses browserify and Babel to build the dist.js file for the client, exporting a single module named ResourcePrefetchTests. Running:

npm run build

will trigger:

browserify -r ./public/entry:ResourcePrefetchTests -d -o public/dist.js

Babel is used for ES2015/ES2016/ES2017 features, such as async/await.

Uses browserify-shim to keep jQuery and Mustache out of dist.js:

    "browserify-shim": {
      "jquery": "global:$",
      "mustache": "global:Mustache"
    }

Uses npm-watch to trigger a build when the source (./public/**/*.js) changes. Running:

npm run watch

will use the following config:

    "watch": {
      "build": {
        "patterns": [
          "public"
        ],
        "extensions": "js",
        "ignore": "public/dist.js",
        "quiet": true
      }
    }

TODO

  • HTTPS

License

MIT © Paul Grime

About

A set of tests for various resource prefetch techniques.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published