Documentation
Requirements
You will need the following free services to use Speedscanner. Alternatives are available, but they will likely require changes to functions (contributions welcome!).
- WebPageTest API key, request one here
- Netlify account
- Fauna account
- IFTTT account
Installation
I. FaunaDB Database
- Create database, no particular name necessary.
- Create an API key from "Security" with "Server" role.
- Make a note of the Key Secret, we will use this later and you can only see it once.
- Create two collections. One will contain page configuration, the other your tests. For example 'site_pages' and 'site_tests'.
- For each collection, add two new indexes. The first should be named as the collection but with
all_
prefixed, all other settings default. The second should be named as the collections but withunique_
prefixed and_id
suffixed. eg,unique_site_pages_id
. Set Terms toid
and check "Unique". - Now we create our configuration documents in our page configuration collection. For each page you want to test, create a document in your pages collection with the following format (excluding comments):
{
"id": "home", // unique identifier for each page
"title": "Home Page", // title for page used in frontend
"url": "https://speedscanner.org", // full URL to test
"freq": 4, // number of hours to leave between each test
"options": {
// custom configuration for WebPageTest.
// for config parameters, see npmjs.com/package/webpagetest
// if not specified, default parameters will be used
}
}
II. Functions and Interface
- Fork this repository into your own GitHub account or organisation.
- In Netlify, create a New Site from Git.
- Select the forked repository
- Click "Show advanced" button above the Deploy site button.
- Set five Environment Variables:
DB_PAGES name of fauna config/pages collection. eg, site_pages
DB_TESTS name of fauna test collection. eg, site_tests
FAUNA_SECRET secret key you created for your fauna database
WPT_KEY API key you obtained from WebPageTest
FORCE_KEY custom secret string, recommended randomised 30-50char
(keep the force key secret, this allows you to manually trigger tests regardless of the cofngured frequency)
- Click deploy
- By default a random URL is created, you can customise this in Settings.
- Once deployed, trigger the first tests by navigating to yourdomain.netlify.com/.netlify/functions/trigger
III. 'Cron' job
This simply needs to be an hourly GET request to yourdomain.netlify.com/.netlify/functions/trigger. To keep with serverless metholody you could use IFTTT or Zapier among others, or you could set up a cron job with curl/wget. The demo above uses an IFTTT applet with a trigger of "Time" and task of "Webhook", that fires a GET requst to the configured address every hour.
If a test is due to run it will be triggered, otherwise it will return with 200 with a message including the next allowed run time.
IV. Customisation (optional)
- Install dependencies with
npm install
- Install netlify dev cli with
npm install netlify-cli -g
- Run with
netlify dev