Stats.js is a lightweight, client-side JavaScript performance monitor designed to display real-time metrics such as Frames Per Second (FPS), milliseconds per frame (MS), and allocated memory (MB) directly in the browser. The current stable version, 0.17.0 (r17), introduced a significant change by converting the library to an ECMAScript module. While its release cadence has historically been irregular, with key updates like `r16` adding `devicePixelRatio` support and `r15` reverting to a more efficient canvas-based rendering, `r17` represents the most recent major shift in its distribution format. It differentiates itself through its minimal footprint and immediate visual feedback, making it an excellent tool for quick performance profiling during development without requiring complex tooling integrations.
npm install stats.jsVerified import paths — ran on the pinned version, not inferred.
This example demonstrates how to initialize Stats.js, append it to the document body, and integrate it into an animation loop to monitor performance metrics like FPS.
Update import statements to `import Stats from 'stats.js';`. Ensure your build environment supports ES modules or use a bundler like Webpack/Rollup.
For Chrome, run the browser with the `--enable-precise-memory-info` flag. Browser support for detailed memory stats can vary.
Always explicitly set `stats.dom.style.position`, `top`, `left`, and `zIndex` if precise control over the monitor's placement is needed, as default styles might change across releases.
Instead of the bookmarklet, embed `stats.js` via npm, a CDN (like unpkg or jsdelivr), or host it locally for reliable access.
Change your code from `var stats = new Stats();` to `import Stats from 'stats.js'; const stats = new Stats();`.
If using v0.17.0 or newer, use `import Stats from 'stats.js';`. If targeting older versions in a browser, ensure `stats.js` is loaded via a `<script>` tag or a compatible bundler.
Ensure `new Stats()` is called and assigned to the `stats` variable before attempting to access its properties. Check for correct `import Stats from 'stats.js';`.
No dependency data recorded yet.