Add Vercel Speed Insights integration - #2
Draft
vercel[bot] wants to merge 1 commit into
Draft
Conversation
## Vercel Speed Insights Implementation
Successfully implemented Vercel Speed Insights for this FastAPI Python project.
### Changes Made
#### Created Files:
1. **package.json** - Added npm package configuration to install @vercel/speed-insights
- Installed version 1.1.0 of @vercel/speed-insights
- Required for the Speed Insights JavaScript library
2. **package-lock.json** - Auto-generated lockfile for npm dependencies
- Ensures consistent dependency versions across environments
#### Modified Files:
1. **main.py** - Added Speed Insights initialization scripts to the HTML response
- Added initialization queue script: `window.si = window.si || function () { (window.siq = window.siq || []).push(arguments); };`
- Added Speed Insights script tag: `<script defer src="/_vercel/speed-insights/script.js"></script>`
- Scripts are injected before the closing `</body>` tag for optimal loading
- Follows the official Vercel documentation pattern for HTML/vanilla JavaScript applications
2. **.gitignore** - Updated to exclude node_modules directory
- Added node_modules/ to prevent committing dependencies
### Implementation Details
Since this is a FastAPI Python project that serves HTML (not a JavaScript framework like React or Next.js), I followed the HTML/vanilla JavaScript integration approach from the official Vercel Speed Insights documentation:
1. **Fetched Latest Documentation**: Retrieved the most up-to-date installation instructions from https://vercel.com/docs/speed-insights/quickstart
2. **Framework-Specific Approach**: Identified that for HTML-based applications, Speed Insights requires:
- The initialization queue function to prepare for tracking
- A deferred script tag that loads from `/_vercel/speed-insights/script.js`
3. **Vercel Integration**: When deployed on Vercel, the Speed Insights script is automatically made available at the `/_vercel/speed-insights/script.js` path, so no additional configuration is needed
### Testing
- ✅ Verified Python syntax is valid (no syntax errors)
- ✅ Confirmed Speed Insights scripts are present in HTML output
- ✅ Tested all API endpoints still work correctly (/api/data, /api/items/{id}, /docs)
- ✅ Verified HTML structure remains valid (DOCTYPE, proper closing tags)
- ✅ Confirmed HTTP 200 responses for all routes
### Next Steps
After deployment to Vercel:
1. Enable Speed Insights in the Vercel Dashboard for this project
2. Deploy the application using `vercel deploy`
3. After users visit the site, performance metrics will appear in the Speed Insights dashboard
4. Speed Insights automatically tracks Core Web Vitals and other performance metrics
### Notes
- Speed Insights does NOT track data in development mode
- The tracking only activates when deployed on Vercel
- No additional environment variables or configuration required
- The integration follows best practices from the official Vercel documentation
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.
Vercel Speed Insights Implementation
Successfully implemented Vercel Speed Insights for this FastAPI Python project.
Changes Made
Created Files:
package.json - Added npm package configuration to install @vercel/speed-insights
package-lock.json - Auto-generated lockfile for npm dependencies
Modified Files:
main.py - Added Speed Insights initialization scripts to the HTML response
window.si = window.si || function () { (window.siq = window.siq || []).push(arguments); };<script defer src="/_vercel/speed-insights/script.js"></script></body>tag for optimal loading.gitignore - Updated to exclude node_modules directory
Implementation Details
Since this is a FastAPI Python project that serves HTML (not a JavaScript framework like React or Next.js), I followed the HTML/vanilla JavaScript integration approach from the official Vercel Speed Insights documentation:
Fetched Latest Documentation: Retrieved the most up-to-date installation instructions from https://vercel.com/docs/speed-insights/quickstart
Framework-Specific Approach: Identified that for HTML-based applications, Speed Insights requires:
/_vercel/speed-insights/script.jsVercel Integration: When deployed on Vercel, the Speed Insights script is automatically made available at the
/_vercel/speed-insights/script.jspath, so no additional configuration is neededTesting
Next Steps
After deployment to Vercel:
vercel deployNotes
View Project · Speed Insights
Created by zedrickriggins174-glitch with Vercel Agent