Skip to main content
A powerful Express middleware for server-side script loading and injection. Load external scripts from remote JSON endpoints with caching, security, and flexible integration options. Built with TypeScript for full type safety.

Installation

Every rendered <script> tag must include a data-code attribute set to your Account ID (verification code). AdUnblock uses this value to verify that the script is running on your registered domain. Find your Account ID at the top of your AdUnblock dashboard.

Quick Start

TypeScript Support

This package is written in TypeScript and provides comprehensive type definitions:

Expected Remote Response Format

Your remote URL should return JSON in this format:

Integration Methods

Use with any template engine (EJS, Handlebars, Pug, etc.):

EJS Example

Handlebars Example

Pug Example

2. Auto Injection

Automatically inject scripts into HTML responses:

3. Manual Injection

Programmatically inject scripts into HTML strings:

4. Direct Access

Access script data directly for custom implementations:

Configuration Options

Advanced Configuration

Route-Specific Configuration

Apply ServerTag to specific routes with different configurations:

API Reference

serverTagMiddleware(options)

Main middleware function that adds ServerTag functionality to Express apps. Parameters:
  • options (ServerTagMiddlewareOptions): Configuration options
Returns: Express middleware function

injectScripts(html, scripts, attributes, position)

Helper function to manually inject scripts into HTML strings. Parameters:
  • html (string): HTML string to modify
  • scripts (string[]): Array of script URLs
  • attributes (ScriptAttributes): Script tag attributes
  • position (string): Where to inject (default: '</head>')
Returns: Modified HTML string

Type Definitions

Error Handling

ServerTag includes robust error handling with custom error types:

Browser Compatibility

ServerTag works with all browsers supported by the generated script tags. The middleware itself runs on Node.js 16+.