-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Pull custom RUM code into its own module
It's a bit surprising to have a bunch of our code tacked on to the end of a vendored file. Our docs say the lux-measurer file "shouldn't ever change", but that feels like a bit of a shaky assumption. In any case, it feels much cleaner to have our code in its own file, instead of muddling it with vendored code. I've use script type=module for two reasons: 1) Like the design system, we can use it as a check that we're in a modern browser, which means we can use const / arrow functions and functions like `.some()` which might not be present in old browsers. For the same reason, we can simplify a lot of the checks around whether the performance API will be there, and whether it will work correctly. 2) It defers the execution of the script, so we'll automatically wait for the HTML to be fully parsed before our code runs. Although we're not interacting with the HTML, I think this should more or less guarantee that (a) the nextHopProtocol timing property is available and (b) the LUX global will already have been defined by lux-measurer.js Just in case (b) isn't always true, I've checked that LUX is defined before attempting to use it. I'm also removing the try / catch code - it doesn't seem like it's doing anything useful even if there is an error, and running as a module the code shouldn't have any reference errors / surprisingly undefined APIs.
- Loading branch information
1 parent
2f86e97
commit d51d4ab
Showing
4 changed files
with
14 additions
and
37 deletions.
There are no files selected for viewing
12 changes: 12 additions & 0 deletions
12
app/assets/javascripts/govuk_publishing_components/rum-custom-data.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
(function () { | ||
/* global LUX, performance */ | ||
if (typeof LUX === 'undefined') { return } | ||
|
||
const navigationPerformance = performance.getEntriesByType('navigation')[0] | ||
if (!navigationPerformance) { return } | ||
|
||
// As per RFC 147[1], this adds in monitoring of the type of HTTP protocol that | ||
// is used when a browser loads a page. | ||
// [1]: https://github.com/alphagov/govuk-rfcs/pull/148 | ||
LUX.addData('http-protocol', navigationPerformance.nextHopProtocol) | ||
}()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters