Skip to content

Commit

Permalink
run DNS tests only on page load
Browse files Browse the repository at this point in the history
Traffic has increased to the point cloudflare is charging for DNS
lookups. I think this will dramatically lower the number of lookups.
  • Loading branch information
benhansen-io committed Jul 16, 2024
1 parent 69014f0 commit da0ef4b
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
2 changes: 1 addition & 1 deletion frontend/about.html
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ <h2 id="dns">DNS Test</h2>
<p>
Test DNS is working by making a HTTP GET request to a [random-number]dns-check.pinging.net.
Caching is explicitly disabled and the random number part of the subdomain prevents common
caching of the DNS lookup. This test is run every 30 seconds.
caching of the DNS lookup. This test is run once when the page is loaded.
</p>

<h2 id="browser">Browser Check</h2>
Expand Down
10 changes: 8 additions & 2 deletions frontend/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ const pingResults: (string | number)[] = [];
// Used to ensure the Last RTT is not overwritten with an older response.
let lastSuccessPingMillis: number | null = null;

// Used to only run the DNS tests once.
var firstTest = true;

let maxPing: number = NaN;
let minPing: number = NaN;
// Used to compute average round trip time and packet loss.
Expand Down Expand Up @@ -424,9 +427,12 @@ async function testHttpOrDns(testName: string) {

function runPeriodicTests() {
updateStatus("http", UNKNOWN);
updateStatus("dns", UNKNOWN);
testHttpOrDns("http");
testHttpOrDns("dns");
if (firstTest) {
updateStatus("dns", UNKNOWN);
testHttpOrDns("dns");
firstTest = false;
}
if (nextPeriodicTests <= Date.now()) {
nextPeriodicTests = Date.now() + PERIODIC_TEST_PERIOD;
}
Expand Down

0 comments on commit da0ef4b

Please sign in to comment.