Express middleware for script loading and injection with TypeScript support
Option | Type | Default | Description |
---|---|---|---|
remoteUrl | string | Required | URL to fetch script configuration from |
cacheInterval | number | 300 | Cache duration in seconds |
injectIntoHtml | boolean | true | Auto-inject scripts into HTML responses |
injectPosition | string | '</head>' | Where to inject scripts in HTML |
scriptAttributes | ScriptAttributes | {async: true} | Additional attributes for script tags |
onError | function | undefined | Custom error handler function |
shouldInject | function | () => true | Conditional injection logic |
serverTagMiddleware(options)
options
(ServerTagMiddlewareOptions): Configuration optionsinjectScripts(html, scripts, attributes, position)
html
(string): HTML string to modifyscripts
(string[]): Array of script URLsattributes
(ScriptAttributes): Script tag attributesposition
(string): Where to inject (default: '</head>'
)