Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion packages/web/src/generic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,18 @@ import { initQueue } from './queue';
import type { SpeedInsightsProps, BeforeSendMiddleware } from './types';
import { computeRoute, getScriptSrc, isBrowser, isDevelopment } from './utils';

/**
* Triggers a fetch call to the specified URL to warm up the endpoint.
* Any errors are silently ignored.
*/
async function warmUpScript(src: string): Promise<void> {
try {
await fetch(src);
} catch (err) {
void 0; // no-op to satisfy non-empty block rules
}
}

/**
* Injects the Vercel Speed Insights script into the page head and starts tracking page views. Read more in our [documentation](https://vercel.com/docs/speed-insights).
* @param [props] - Speed Insights options.
Expand Down Expand Up @@ -65,7 +77,9 @@ function injectSpeedInsights(
);
};

document.head.appendChild(script);
void warmUpScript(src).finally(() => {
document.head.appendChild(script);
});

return {
setRoute: (route: string | null): void => {
Expand Down