or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

docs

bundle-usage.mddynamic-loading.mdes5-adapter.mdevent-system.mdindex.md
tile.json

bundle-usage.mddocs/

Complete Polyfill Bundle

The webcomponents-bundle.js contains all Web Components polyfills in a single file, providing the simplest integration option for applications that don't require loading optimization.

Capabilities

Bundle Script

Complete polyfill bundle that loads all Web Components APIs immediately.

/**
 * Include webcomponents-bundle.js as a script tag
 * All polyfills load immediately, no feature detection performed
 * Each polyfill activates only if needed based on browser support
 */
// <script src="webcomponents-bundle.js"></script>

// After bundle loads, all Web Components APIs are available
// WebComponentsReady event fires when initialization is complete

Usage Examples:

<!-- Simple bundle usage -->
<script src="webcomponents-bundle.js"></script>
<script type="module" src="my-element.js"></script>
<my-element></my-element>

<!-- CDN usage -->
<script src="https://unpkg.com/@webcomponents/webcomponentsjs@^2/webcomponents-bundle.js"></script>
<script type="module" src="my-element.js"></script>

Included Polyfills

The bundle contains all available polyfills but only activates those needed by the browser.

Core Web Components Polyfills:

  • Custom Elements v1: window.customElements API
  • Shadow DOM v1: ShadyDOM and ShadyCSS polyfills
  • HTMLTemplateElement: Template element support

Platform Polyfills (for IE 11 and older browsers):

  • Promise: ES6 Promise implementation
  • Event Constructors: Event, CustomEvent, MouseEvent constructors
  • Object.assign: Object property copying
  • Array.from: Array creation from iterables
  • Symbol: ES6 Symbol primitive
  • URL Constructor: URL API implementation

Bundle Loading Behavior

Unlike the dynamic loader, the bundle loads all polyfill code but conditionally applies it.

/**
 * Bundle loading sequence:
 * 1. All polyfill code loads immediately
 * 2. Each polyfill checks if native implementation exists
 * 3. Polyfills only activate if native support is missing
 * 4. WebComponentsReady event fires when complete
 */

// WebComponentsReady event
interface WebComponentsReadyEvent extends CustomEvent {
  type: 'WebComponentsReady';
  bubbles: true;
}

Usage Examples:

// Wait for bundle initialization
document.addEventListener('WebComponentsReady', () => {
  // All polyfills loaded and custom elements upgraded
  console.log('Web Components ready!');
});

// Check readiness programmatically
if (window.WebComponents && window.WebComponents.ready) {
  // Already ready
} else {
  // Wait for ready event
  document.addEventListener('WebComponentsReady', handler);
}

Bundle vs Loader Comparison

webcomponents-bundle.js Benefits:

  • Simpler integration (single script tag)
  • No async coordination needed
  • Consistent behavior across browsers
  • Works with traditional script loading

webcomponents-bundle.js Drawbacks:

  • Larger initial payload (~50KB+ vs ~2KB loader)
  • Loads unused polyfill code on modern browsers
  • Less optimal for performance-critical applications

When to Use Bundle:

  • Rapid prototyping or development
  • Simple applications without complex loading requirements
  • Legacy build systems that can't handle dynamic loading
  • Applications where the extra payload is acceptable

When to Use Loader:

  • Production applications prioritizing performance
  • Progressive web apps with strict payload budgets
  • Applications with complex loading sequences
  • Modern build systems with code splitting

Integration Patterns

Traditional Script Loading

<!DOCTYPE html>
<html>
<head>
  <!-- Load bundle in head -->
  <script src="webcomponents-bundle.js"></script>
</head>
<body>
  <!-- Custom elements available immediately -->
  <script type="module" src="my-element.js"></script>
  <my-element></my-element>
</body>
</html>

Module Loading

<!-- Bundle first -->
<script src="webcomponents-bundle.js"></script>

<!-- Then modules -->
<script type="module">
  import './my-element.js';
  
  // Use custom elements immediately
  document.body.appendChild(document.createElement('my-element'));
</script>

Framework Integration

// React/Vue/Angular applications
// Include bundle via script tag or webpack

// In your component code:
import { LitElement, html } from 'lit';

class MyElement extends LitElement {
  render() {
    return html`<p>Custom element works!</p>`;
  }
}
customElements.define('my-element', MyElement);

File Size and Performance

Bundle Sizes (approximate):

  • webcomponents-bundle.js: ~65KB minified
  • webcomponents-loader.js: ~2KB minified
  • Individual bundles: 15-45KB depending on included polyfills

Loading Performance:

  • Bundle: Single HTTP request, immediate availability
  • Loader: 2 HTTP requests (loader + detected bundle), async coordination

Runtime Performance:

  • Bundle: No performance difference once loaded
  • Loader: Identical runtime performance

Error Handling

// Handle bundle loading errors
const script = document.createElement('script');
script.src = 'webcomponents-bundle.js';
script.addEventListener('load', () => {
  console.log('Bundle loaded successfully');
});
script.addEventListener('error', () => {
  console.error('Failed to load Web Components bundle');
  // Fallback strategy here
});
document.head.appendChild(script);

The bundle itself handles polyfill initialization errors internally and will log warnings for any issues encountered during polyfill activation.