--- title: Boostify Documentation description: JavaScript toolkit for web performance optimization version: latest last_updated: 2026-01-31 url: https://boostifyjs.com/llms.txt full_documentation: https://boostifyjs.com/llms-full.txt --- # Boostify > A JavaScript toolkit for web performance optimization. Load scripts, styles, and media on-demand using smart triggers. ## Quick Links - Website: https://boostifyjs.com/ - Repository: https://github.com/andresclua/boostify - NPM: https://www.npmjs.com/package/boostify ## Installation ```bash npm install boostify ``` ```javascript import Boostify from 'boostify'; const bstf = new Boostify({ debug: true, license: "YOUR-LICENSE-KEY" }); ``` Or via CDN: ```html ``` --- ## API Reference ### Content Injection Methods #### loadScript(options) Dynamically inject JavaScript files or inline scripts. ```javascript await bstf.loadScript({ url: 'https://cdn.example.com/library.js', appendTo: 'head', attributes: ["id=my-script", "data-custom=value"] }); // Or inline script await bstf.loadScript({ inlineScript: `console.log('Hello');`, appendTo: 'body' }); ``` **Options:** - `url` (string): URL of the script to load - `inlineScript` (string): Inline JavaScript to execute - `appendTo` (string|Element): Where to append ('head', 'body', or DOM element) - `attributes` (array): Additional attributes ["key=value"] #### loadStyle(options) Dynamically inject CSS files or inline styles. ```javascript await bstf.loadStyle({ url: 'https://cdn.example.com/styles.css', appendTo: 'head' }); // Or inline styles await bstf.loadStyle({ inlineStyle: `.my-class { color: red; }`, appendTo: 'head' }); ``` **Options:** - `url` (string): URL of the stylesheet - `inlineStyle` (string): Inline CSS to inject - `appendTo` (string|Element): Where to append #### videoEmbed(options) Lazy-load video embeds (YouTube, Vimeo) with performance optimization. #### videoPlayer(options) Native video player with lazy loading and performance features. --- ### Trigger Events #### onScroll(options) Execute callbacks when user scrolls to a specific point. ```javascript bstf.onScroll({ callback: () => { console.log('User scrolled past threshold'); }, threshold: 500 // pixels from top }); ``` #### onClick(options) Execute callbacks on element click. ```javascript bstf.onClick({ selector: '.load-more-btn', callback: async () => { await bstf.loadScript({ url: 'heavy-feature.js' }); } }); ``` #### observer(options) Execute callbacks when elements enter the viewport (Intersection Observer). ```javascript bstf.observer({ selector: '.lazy-component', callback: (element) => { element.classList.add('visible'); }, threshold: 0.5 // 50% visible }); ``` #### inactivity(options) Detect user inactivity or browser idle state. ```javascript // User idle mode - tracks mouse, keyboard, scroll bstf.inactivity({ callback: () => { console.log('User inactive for 5 seconds'); }, idleTime: 5000, name: 'my-idle-detector' }); // Native idle mode - uses requestIdleCallback bstf.inactivity({ callback: () => { performBackgroundTasks(); }, maxTime: 3000, name: 'background-tasks' }); // Destroy instance bstf.destroyinactivity({ name: 'my-idle-detector' }); ``` **Options:** - `callback` (function): Function to execute - `idleTime` (number): Ms of inactivity before triggering (user mode) - `maxTime` (number): Maximum wait time in ms - `events` (array|'none'): Events to monitor, or 'none' to disable - `name` (string): Instance identifier (required for destroy) - `debug` (boolean): Enable console logging #### onLoad(options) Execute callbacks after DOM/page load events. Best for third-party scripts. --- ## Common Use Cases ### Lazy Load Third-Party Scripts ```javascript // Load analytics only after user interaction bstf.onScroll({ threshold: 100, callback: async () => { await bstf.loadScript({ url: 'https://analytics.com/script.js' }); } }); ``` ### Load Heavy Features On-Demand ```javascript bstf.onClick({ selector: '#open-chat', callback: async () => { await bstf.loadScript({ url: 'chat-widget.js' }); await bstf.loadStyle({ url: 'chat-widget.css' }); initChatWidget(); } }); ``` ### Auto-Logout on Inactivity ```javascript bstf.inactivity({ callback: () => { if (confirm('Session expiring. Stay logged in?')) { resetSession(); } else { window.location.href = '/logout'; } }, idleTime: 300000, // 5 minutes name: 'session-timeout' }); ``` ### Defer Non-Critical Work ```javascript bstf.inactivity({ callback: () => { prefetchNextPageAssets(); syncAnalyticsData(); }, events: 'none', // Use native idle detection only maxTime: 5000, name: 'background-sync' }); ``` --- ## Performance Benefits - **Reduced Initial Load**: Load resources only when needed - **Improved Core Web Vitals**: Better LCP, FID, CLS scores - **Smart Resource Loading**: Trigger-based loading strategies - **Browser-Friendly**: Uses native APIs like Intersection Observer and requestIdleCallback --- ## Documentation Pages ### Guides - [Install](https://boostifyjs.com/guides/install/): Install Boostify in your project - [Introduction](https://boostifyjs.com/guides/introduction/): Why Boostify? ### Content Injection - [Load Javascript](https://boostifyjs.com/content-injection/load-script/): Dynamically injects a javascript file into a page or adds elements using the ``` ## Configuration | Option | Type | Default | Description | |--------|------|---------|-------------| | `debug` | Boolean | `false` | Enable colorful console logging for debugging | ## Debug Mode When `debug: true`, you'll see colorful logs in your browser console with emojis and gradients: | 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 | This makes it easy to see exactly what Boostify is doing and when. ## What's Next? With Boostify installed, you can: - [Load third-party scripts efficiently](/trigger-events/on-load/) with the proxy feature - [Trigger events on scroll](/trigger-events/on-scroll/) - [Inject scripts on click](/trigger-events/on-click/) - [Detect user inactivity](/trigger-events/inactivity/) --- ### Introduction URL: https://boostifyjs.com/guides/introduction/ Why Boostify? Modern websites need to be **fast** β€” both in loading time and interaction. I created this library with one main goal in mind: to make it easy for developers to **manage key performance features without adding complexity**. From injecting styles and scripts to embedding videos and triggering events at the right moment, everything is designed to be straightforward and developer-friendly. One of the main challenges was bringing all these tools into a single, well-structured library. But doing so turned out to be incredibly useful β€” not only for improving performance but also for **simplifying development workflows**. Since Google PageSpeed plays a big role in how sites are ranked, we also included a utility to fetch performance scores from your site with minimal setup. ## Feedback We welcome all types of feedback β€” whether it's about improving the codebase, fixing bugs, or suggesting new features. The goal is to build a tool that's truly helpful for everyone. ## Next steps - [Install Boostify](/guides/install/) - Get started in minutes - [On Load Events](/trigger-events/on-load/) - Defer third-party scripts - [Load Scripts](/content-injection/load-script/) - Dynamic script injection - [Load Styles](/content-injection/load-style/) - Dynamic CSS injection ## From the blog - [Boostify is Now Free](/blog/boostify-is-now-free/) - Our open source announcement - [Load Third-Party Scripts via Proxy](/blog/third-party-scripts-proxy/) - New proxy feature - [Core Web Vitals and the Funnel](/blog/core-web-vitals-marketing-funnel/) - Why performance matters --- ### Load Javascript URL: https://boostifyjs.com/content-injection/load-script/ Dynamically injects a javascript file into a page or adds elements using the ``` To this: ```html ``` ### Step 3: Call onload ```js bstf.onload({ worker: true, callback: (result) => { console.log('Scripts loaded!', result); } }); ``` That's it. Your scripts now load without blocking your page. --- ## Complete Example Here's a full example with Google Analytics: ```html

My Fast Website

``` --- ## When Do Scripts Load? Scripts load when **any** of these happen: | Event | What it means | |-------|---------------| | User moves mouse | They're actively browsing | | User scrolls | They're reading your content | | User touches screen | Mobile interaction | | Max time reached | Fallback after X milliseconds | This means: scripts load when the user is engaged, not when they're waiting for your page. --- ## Configuration Options ```js bstf.onload({ worker: true, // Use proxy (recommended) maxTime: 2000, // Wait max 2 seconds eventsHandler: ['mousemove', 'scroll', 'touchstart'], callback: (result) => { } }); ``` | Option | Default | What it does | |--------|---------|--------------| | `worker` | `false` | `true` = load via Boostify proxy (faster, recommended) | | `maxTime` | `600` | Max milliseconds to wait before loading anyway | | `eventsHandler` | `['mousemove', 'load', 'scroll', 'touchstart']` | Which user actions trigger loading | | `callback` | `null` | Function called when done | --- ## The `worker` Option Explained When `worker: true`, Boostify loads scripts through our proxy server. This has two benefits: 1. **Faster loading**: Scripts are fetched in a separate thread 2. **No main thread blocking**: Your page stays responsive ```js // Without worker (traditional) bstf.onload({ worker: false }); // Scripts load directly from Google, Facebook, etc. // With worker (recommended) bstf.onload({ worker: true }); // Scripts load via Boostify's proxy ``` ### Supported Services The proxy works with all major tracking services: | Service | Works? | |---------|--------| | Google Tag Manager | Yes | | Google Analytics | Yes | | Facebook Pixel | Yes | | Microsoft Clarity | Yes | | Hotjar | Yes | | LinkedIn Insight | Yes | | TikTok Analytics | Yes | | jsDelivr, unpkg, cdnjs | Yes | ### What if my service is not listed? Don't worry, you have options: 1. **Use `worker: false`** - Your scripts still load deferred, just not through the proxy: ```js bstf.onload({ worker: false }); // Works with ANY script ``` 2. **Request the domain** - Open an issue on [GitHub](https://github.com/andresclua/boostify/issues) and we'll add it to the proxy whitelist. 3. **Automatic fallback** - If you use `worker: true` with an unsupported domain, Boostify automatically falls back to traditional loading. Nothing breaks. --- ## Understanding the Callback The callback tells you exactly what happened: ```js bstf.onload({ worker: true, callback: (result) => { console.log(result); } }); ``` Result example: ```js { success: true, // Did it work? method: 'worker', // 'worker' or 'traditional' loadTime: 245, // How long it took (ms) triggeredBy: 'mousemove', // What triggered loading scripts: [ { url: 'https://googletagmanager.com/gtag/js', success: true, type: 'external', proxied: true }, { success: true, type: 'inline' } ] } ``` --- ## Common Questions ### Will this break my analytics? No. The scripts run exactly the same, just later. Your analytics will still track everything. ### Will I lose conversions? You might see 0.5-2% fewer tracked pageviews on very fast bounces. But your site will be faster, which typically **increases** conversions overall. ### What if the proxy is down? Boostify automatically falls back to traditional loading. Your scripts always load. ### Can I use this with any script? Yes, but it's designed for third-party tracking scripts. Don't use it for scripts your page needs immediately (like React or Vue). --- ## More Examples ### Google Analytics 4 ```html ``` ### Facebook Pixel ```html ``` ### Hotjar ```html ``` ### Microsoft Clarity ```html ``` --- ## Recommendation: Use Google Tag Manager Instead of adding multiple scripts with `type="text/boostify"`, we recommend using **Google Tag Manager (GTM) as your single container**. ### Why? 1. **One script to load** - GTM loads once through the proxy, everything else loads inside GTM 2. **Easier management** - Add/remove tags from GTM's interface, no code changes needed 3. **Better performance** - One proxy request instead of multiple 4. **Full functionality** - All tags inside GTM work normally (cookies, tracking, pixels) ### How it works ```html ``` Then add all your other tags (Analytics, Facebook Pixel, Hotjar, HubSpot, etc.) inside GTM. ### What happens behind the scenes 1. Boostify loads GTM through the proxy (background, doesn't block) 2. GTM starts and loads your configured tags 3. Those tags load normally and work 100% (cookies, tracking, everything) The key benefit: **GTM starts late**, so all its child tags also start late. Your page is already interactive before any tracking begins. --- ## Related - [On Scroll Events](/trigger-events/on-scroll/) - Scroll-based triggers - [Observer Events](/trigger-events/observer/) - Visibility-based triggers - [On Click Events](/trigger-events/on-click/) - User interaction triggers - [Inactivity Detection](/trigger-events/inactivity/) - User inactivity triggers - [Load Script](/content-injection/load-script/) - Dynamic script injection - [How to Load Analytics Without Slowing Down Your Site](/blog/third-party-scripts-proxy/) - Full guide