{"library":"polyfill-bundler","title":"Polyfill Bundler Service","description":"Polyfill Bundler is a JavaScript utility package that enables the creation and hosting of a dynamic polyfill service. This service intelligently delivers custom polyfill bundles to clients based on their user-agent string and explicitly requested features, ensuring that browsers only receive the JavaScript code necessary to support modern web standards. This approach contrasts with static bundling, which often includes all polyfills regardless of need, leading to unnecessary payload size. The package is currently at version 1.0.126, suggesting ongoing development with frequent updates to its minor and patch versions. It is primarily designed for developers who wish to host their own polyfill service to optimize client-side performance and ensure broad browser compatibility without over-bundling. The core differentiator is its on-demand, user-agent-aware polyfill generation, reducing load times for modern browsers while providing full functionality for older ones. [17, 21]","language":"javascript","status":"active","last_verified":"Tue Apr 21","install":{"commands":["npm install polyfill-bundler"],"cli":null},"imports":[],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"<!-- Include this in your HTML to use the self-hosted polyfill service -->\n<script src=\"https://polyfill.your.domain/polyfill.js?features=AbortController,Array.from,Promise.prototype.finally\"></script>\n\n// Example of how to start a very basic (not production-ready) Node.js server\n// that could theoretically serve polyfills, assuming polyfill-bundler provides\n// an API to generate them. (Note: The exact API for 'polyfill-bundler' as a library\n// to generate bundles programmatically is not directly exposed in the README snippet;\n// this is a conceptual server illustrating the client-side usage.)\n\nconst http = require('http');\nconst url = require('url');\n\n// In a real application, 'polyfill-bundler' would be used here to generate the bundle.\n// For this example, we'll simulate a response.\nfunction generatePolyfillBundle(features) {\n  console.log(`Generating polyfill for features: ${features.join(', ')}`);\n  // In a real scenario, this would use the polyfill-bundler logic\n  // to detect user-agent and generate a minified, targeted polyfill string.\n  // For demonstration, a simple placeholder.\n  let bundle = '';\n  if (features.includes('AbortController')) bundle += '/* AbortController polyfill */\\nself.AbortController = self.AbortController || function AbortController() { this.signal = { aborted: false }; };\\n';\n  if (features.includes('Array.from')) bundle += '/* Array.from polyfill */\\nif (!Array.from) { Array.from = (iterable) => [...iterable]; }\\n';\n  if (features.includes('Promise.prototype.finally')) bundle += '/* Promise.finally polyfill */\\nif (!Promise.prototype.finally) { Promise.prototype.finally = function(cb) { const P = this.constructor || Promise; return this.then(val => P.resolve(cb()).then(() => val), err => P.resolve(cb()).then(() => { throw err; })); }; }\\n';\n  return bundle;\n}\n\nconst server = http.createServer((req, res) => {\n  const parsedUrl = url.parse(req.url, true);\n  if (parsedUrl.pathname === '/polyfill.js') {\n    const featuresParam = parsedUrl.query.features;\n    const features = featuresParam ? featuresParam.split(',') : [];\n\n    const polyfillCode = generatePolyfillBundle(features);\n\n    res.writeHead(200, { 'Content-Type': 'application/javascript' });\n    res.end(polyfillCode);\n  } else {\n    res.writeHead(404, { 'Content-Type': 'text/plain' });\n    res.end('Not Found');\n  }\n});\n\nconst PORT = process.env.PORT ?? 3000;\nserver.listen(PORT, () => {\n  console.log(`Polyfill service running at http://localhost:${PORT}`);\n  console.log('Access via: http://localhost:3000/polyfill.js?features=AbortController,Array.from');\n});","lang":"javascript","description":"Demonstrates the client-side consumption of the `polyfill-bundler` service via a script tag, along with a conceptual Node.js server illustrating how such a service would dynamically generate polyfill bundles based on requested features. This quickstart highlights the primary use case of `polyfill-bundler` as a self-hostable service for optimizing polyfill delivery. [17]","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}