Free & Open Source - No license required.
Boostify is a lightweight JavaScript library that improves website performance by deferring third-party scripts and loading resources on demand.
Third-party scripts (Google Analytics, Facebook Pixel, Hotjar, etc.) block your main thread and slow down your site. Boostify loads them in the background after your page is interactive.
npm install boostifyimport Boostify from 'boostify';
const bstf = new Boostify({ debug: true });<script src="https://unpkg.com/boostify@latest/dist/Boostify.umd.js"></script>
<script>
const bstf = new Boostify({ debug: true });
</script>Change type="text/javascript" to type="text/boostify":
<script type="text/boostify" src="https://www.googletagmanager.com/gtag/js?id=G-XXXXX"></script>
<script type="text/boostify">
window.dataLayer = window.dataLayer || [];
window.gtag = function(){dataLayer.push(arguments);}
window.gtag('js', new Date());
window.gtag('config', 'G-XXXXX');
</script>const bstf = new Boostify({ debug: true });
bstf.onload({
worker: true, // Load via proxy (recommended)
callback: (result) => {
console.log('Scripts loaded!', result);
}
});That's it. Your analytics load in the background without blocking your page.
When debug: true, you'll see colorful logs in your console with emojis:
| Event | Emoji | Color |
|---|---|---|
| Boostify init | π | Purple gradient |
| OnLoad | β‘ | Purple/violet |
| Click | π | Pink/coral |
| Scroll | π | Green/turquoise |
| Observer | ποΈ | Cyan/blue |
| Inactivity | π€ | Pink/yellow |
| Script loaded | π¦ | Bright green |
| Style loaded | π¨ | Pink |
Instead of multiple scripts, use GTM as a single container:
<script type="text/boostify" src="https://www.googletagmanager.com/gtm.js?id=GTM-XXXXX"></script>Then add all your tags (Facebook Pixel, Hotjar, HubSpot, etc.) inside GTM. One proxy request, everything works normally.
| Method | Description |
|---|---|
bstf.onload() |
Defer third-party scripts until page is interactive |
bstf.scroll() |
Fire callback when user scrolls to a distance |
bstf.click() |
Fire callback on element click |
bstf.observer() |
Fire callback when element enters viewport |
bstf.inactivity() |
Fire callback when user is inactive |
| Method | Description |
|---|---|
bstf.loadScript() |
Dynamically inject JavaScript |
bstf.loadStyle() |
Dynamically inject CSS |
bstf.videoPlayer() |
Inject HTML5 video player |
bstf.videoEmbed() |
Inject YouTube/Vimeo embed |
bstf.scroll({
distance: 300,
callback: async () => {
await bstf.loadScript({
url: 'https://example.com/library.js',
appendTo: 'body'
});
}
});bstf.click({
element: document.getElementById('load-chat'),
callback: async () => {
await bstf.loadScript({
url: 'https://example.com/chat-widget.js',
appendTo: 'body'
});
}
});bstf.observer({
element: document.querySelector('.lazy-section'),
callback: async () => {
await bstf.loadStyle({
url: 'https://example.com/section-styles.css',
appendTo: 'head'
});
}
});bstf.inactivity({
idleTime: 5000,
name: 'my-inactivity',
callback: () => {
console.log('User has been inactive for 5 seconds');
}
});When using worker: true, these services load through Boostify's proxy:
- Google Tag Manager
- Google Analytics
- Facebook Pixel
- Microsoft Clarity
- Hotjar
- LinkedIn Insight
- TikTok Analytics
- HubSpot
- jsDelivr, unpkg, cdnjs
Services not listed? Use worker: false (still deferred, just not proxied) or request the domain.
Full documentation at boostifyjs.com
- On Load Events
- Scroll Events
- Click Events
- Observer Events
- Inactivity Detection
- Load Script
- Load Style
Changed
- Library is now free and open source (no license required)
- Added
workeroption toonload()for proxy-based loading - Added Web Worker support for background script fetching
- Callback now receives detailed result object (loadTime, method, scripts, etc.)
- Renamed
destroyNoMatterWhat()todestroyAll()
Changed
- Library Validation
Changed
- Enhanced inactivity detection with dual-mode support (user idle/native idle)
- Added
maxTimeparameter for better idle timeout control - Breaking:
destroyinactivity()now requires event name parameter
Improved
- Event listeners now use passive mode for better performance
- More robust timer cleanup with centralized management
Changed
- Fix autoplay true/false in videoplayer
Changed
- Refactored event handling
- Added user inactivity detection feature
Changed
- Issue #2 fixed
Changed
- Updated
package.jsonto resolve Netlify build issues