Skip to main content

Add a note to the Datasette footer measuring the total page load time

Project description

datasette-total-page-time

PyPI Changelog Tests License

Add a note to the Datasette footer measuring the total page load time

Installation

Install this plugin in the same environment as Datasette.

datasette install datasette-total-page-time

Usage

Once this plugin is installed, a note will appear in the footer of every page showing how long the page took to generate.

Queries took 326.74ms · Page took 386.310ms

How it works

Measuring how long a page takes to load and then injecting that note into the page is tricky, because you need to finish generating the page before you know how long it took to load it!

This plugin uses the asgi_wrapper plugin hook to measure the time taken by Datasette and then inject the following JavaScript at the bottom of the response, after the closing </html> tag but with the correct measured value:

<script>
let footer = document.querySelector("footer");
if (footer) {
    let ms = 37.224;
    let s = ` &middot; Page took ${ms.toFixed(3)}ms`;
    footer.innerHTML += s;
}
</script>

This script is injected only on pages with the text/html content type - so it should not affect JSON or CSV returned by Datasette.

Development

To set up this plugin locally, first checkout the code. Then create a new virtual environment:

cd datasette-total-page-time
python3 -mvenv venv
source venv/bin/activate

Now install the dependencies and test dependencies:

pip install -e '.[test]'

To run the tests:

pytest

Project details


Release history Release notifications | RSS feed

This version

0.1

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

datasette-total-page-time-0.1.tar.gz (6.9 kB view details)

Uploaded Source

Built Distribution

datasette_total_page_time-0.1-py3-none-any.whl (7.6 kB view details)

Uploaded Python 3

File details

Details for the file datasette-total-page-time-0.1.tar.gz.

File metadata

File hashes

Hashes for datasette-total-page-time-0.1.tar.gz
Algorithm Hash digest
SHA256 ca5466fe5d894bdb4cf10b057f2070fdf3789d2af43c7c842ec1c47de344449a
MD5 fb260b990f65ecac76e3b1ddda5a927c
BLAKE2b-256 252d432099d52fe682ee227a4cfcdff8018b3647e3428d7de9f43af485deff3c

See more details on using hashes here.

File details

Details for the file datasette_total_page_time-0.1-py3-none-any.whl.

File metadata

File hashes

Hashes for datasette_total_page_time-0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 6b21682605417bbef4da31b81e1af6233e5126488eaba5b747e51d90392c0fa0
MD5 e28857e1667c7ab9b154c0217a2ebf07
BLAKE2b-256 aa20541417048ac6cd326799a4dd8348e86cd50b2512f26e5333e9195fe579b1

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page