Add Vercel Speed Insights integration - #6
Draft
vercel[bot] wants to merge 1 commit into
Draft
Conversation
Implemented Vercel Speed Insights for the wechat-workflow project. ## Summary Successfully installed and configured Vercel Speed Insights following the latest official documentation from https://vercel.com/docs/speed-insights/quickstart. ## Changes Made ### 1. Package Installation - Installed `@vercel/speed-insights` version 2.0.0 - Added dependency to package.json - Updated package-lock.json with new package and its 87 dependencies ### 2. Server Configuration (server.js) - Added a new route to serve the Speed Insights script from node_modules - Route: `GET /_vercel/speed-insights/script.js` - This serves the browser-compatible ES module from `@vercel/speed-insights/dist/index.mjs` - Positioned before the static file middleware to ensure proper handling ### 3. Client Integration (public/index.html) - Added a module script tag at the end of the HTML body - Imported and initialized Speed Insights using `injectSpeedInsights()` function - Used ES6 module syntax with type="module" for browser compatibility ## Implementation Details Since this is an Express application serving a vanilla JavaScript single-page application (SPA), I implemented the framework-agnostic approach: 1. The Speed Insights library is served directly from node_modules via an Express route 2. The HTML file loads it as an ES module 3. The `injectSpeedInsights()` function is called immediately to initialize tracking This approach: - Does not require a build step or bundler - Preserves the existing code structure - Works seamlessly with the Express server setup - Automatically tracks web vitals and performance metrics when deployed to Vercel ## Testing Performed ✅ **npm test**: All smoke tests passed (template conversions working correctly) ✅ **Server startup**: Server starts without errors on port 3000 ✅ **Script endpoint**: Speed Insights script is accessible at /_vercel/speed-insights/script.js ✅ **HTML validation**: HTML file is valid and properly formatted ## Notes - Speed Insights will only track data in production mode (not in development) - The analytics data will be visible in the Vercel dashboard once the app is deployed - No additional configuration is required; Speed Insights works out of the box with default settings - The implementation uses the official Vercel Speed Insights package (v2.0.0) as of June 2026 Co-authored-by: Vercel <vercel[bot]@users.noreply.github.com>
Author
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Implemented Vercel Speed Insights for the wechat-workflow project.
Summary
Successfully installed and configured Vercel Speed Insights following the latest official documentation from https://vercel.com/docs/speed-insights/quickstart.
Changes Made
1. Package Installation
@vercel/speed-insightsversion 2.0.02. Server Configuration (server.js)
GET /_vercel/speed-insights/script.js@vercel/speed-insights/dist/index.mjs3. Client Integration (public/index.html)
injectSpeedInsights()functionImplementation Details
Since this is an Express application serving a vanilla JavaScript single-page application (SPA), I implemented the framework-agnostic approach:
injectSpeedInsights()function is called immediately to initialize trackingThis approach:
Testing Performed
✅ npm test: All smoke tests passed (template conversions working correctly)
✅ Server startup: Server starts without errors on port 3000
✅ Script endpoint: Speed Insights script is accessible at /_vercel/speed-insights/script.js
✅ HTML validation: HTML file is valid and properly formatted
Notes
View Project · Speed Insights
Created by Dong Ke (baiheinet) with Vercel Agent