Skip to content

The utilities in this repo use Performance.getEntriesByType("resource") data from the browser to try and determine if the page (and its resources) was loaded from cache.

License

Notifications You must be signed in to change notification settings

gitgrimbo/cache-flow-problems

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

About

The utilities in this repo use Performance.getEntriesByType("resource") data from the browser to try and determine if the page (and its resources) was loaded from cache.

The Resource Timing spec is available at https://www.w3.org/TR/resource-timing/.

The main objectives of this repo are to provide ways to

  • capture Performance.getEntriesByType("resource") data from a web page.
  • provide an is-page-cached API that uses the captured data.

Results

To see the sorts of results captured: https://gitgrimbo.github.io/cache-flow-problems/.


Usage

API

const api = require("./src/shared/cache-query");
let entries = performance.getEntriesByType("resource");
entries = entries.filter(/* filter resources as required */);

// No options
// Only visits that strictly have all (duration === 0ms)
// and/or accessible (transferSize === 0) are considered cached.
api.areEntriesCached(entries);

// With options
// E.g. treat durations less than 5ms as cached.
api.areEntriesCached(entries, {
  durationThreshold: {
    cachedIfLowerThan: 5
  }
});

// With options
// E.g. treat durations greater than 50ms as uncached.
api.areEntriesCached(entries, {
  durationThreshold: {
    uncachedIfHigherThan: 50
  }
});

Capturing data 1 - Functional tests

Functional tests are used to capture Performance.getEntriesByType("resource") data from a test web page.

Start local Selenium. E.g. if you have downloaded Selenium Standalone, run:

java -jar selenium-server-standalone-x.y.z.jar

Run the tests. This will run tests, gather data, and submit to the capture server. Edit the environments property in intern-functional-standalone.js for the browsers you have installed.

Capturing data 2 - Bookmarklet

See Client.


Components

There are several components:

  • A client JS file that can be inserted into the PUT (page under test) to beacon back resource data.
  • A bookmarklet JS file that can be run manually on the PUT if the PUT has a strict CSP (Content Security Policy) (i.e. does not allow 3rd party scripts).
  • A capture server that receives and saves the beaconed resource data.
  • CLI apps to query the stored resource data.

Those components are documented individually:


How to determine if a resource was loaded from cache?

First, the browser needs to support the Resource Timing API:

As of 21/07/2016 the most obvious omissions are IE9, Safari, iOS Safari and Opera Mini.

Next, the browser will only expose certain timings according to cross-origin restrictions:

  • Same-domain resource: All timings available.
  • Cross-origin resource: Following timings not available without an explicit Timing-Allow-Origin HTTP response header.
    • redirectStart, redirectEnd, domainLookupStart, domainLookupEnd, connectStart, connectEnd, requestStart, responseStart, and secureConnectionStart.

There is no specific API to determine if a resource was served from browser cache, so the following generalisations must be made:

License

MIT © Paul Grime

About

The utilities in this repo use Performance.getEntriesByType("resource") data from the browser to try and determine if the page (and its resources) was loaded from cache.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published