Under Development: These PHP packages are currently under active development. If you need immediate support or have specific requirements, please contact our support team for assistance.
Server-side script loading packages for PHP applications, providing secure, cached script loading with framework-specific integrations for Laravel and Symfony.

Available Frameworks

Laravel

Blade helper function with built-in caching and auto-discovery

Symfony

Twig extension with dependency injection and bundle structure

Expected Remote Response Format

All PHP packages expect the remote URL to return JSON in this format:
{
  "js": ["https://example.com/script1.js", "https://example.com/script2.js"]
}

Laravel Integration

A Laravel package to fetch and render scripts from a remote URL with caching support.

Installation

Install the package via Composer:
composer require adunblock/server-tag-laravel
The package will be automatically registered via Laravel’s package auto-discovery feature.

Basic Usage

In your Blade template, you can now use the server_tag function:
<!DOCTYPE html>
<html>
<head>
  <title>My Page</title>
  {!! server_tag('https://config.adunblocker.com/server-tag.json') !!}
</head>
<body>
  <h1>My Page</h1>
</body>
</html>

Custom Rendering

You can provide a custom closure to the render_script argument to render the script tags in a different way:
<!DOCTYPE html>
<html>
<head>
  <title>My Page</title>
  {!!
    server_tag('https://config.adunblocker.com/server-tag.json', 300, function($jsFiles) {
      $scripts = array_map(function ($src) {
        return "<script src=\"{$src}\" defer></script>";
      }, $jsFiles['js'] ?? []);
      return implode("\n", $scripts);
    })
  !!}
</head>
<body>
  <h1>My Page</h1>
</body>
</html>

Laravel Features

  • Blade Helper Function: Easy-to-use function for templates
  • Built-in Caching: Automatic caching with configurable TTL
  • Auto-discovery: Automatic service provider registration
  • Error Handling: Graceful fallback to empty arrays
  • Security: XSS protection with proper HTML escaping

Laravel Requirements

  • PHP 7.4 or higher
  • Laravel 8/9/10/11

Symfony Integration

A Symfony bundle to fetch and render scripts from a remote URL with Twig integration and caching support.

Installation

Install the bundle via Composer:
composer require adunblock/server-tag-symfony
Enable the bundle in your config/bundles.php:
<?php

return [
    // ... other bundles
    Adunblock\ServerTag\Symfony\AdunblockServerTagBundle::class => ['all' => true],
];

Basic Usage

In your Twig template, you can now use the server_tag function:
<!DOCTYPE html>
<html>
<head>
  <title>My Page</title>
  {{ server_tag('https://config.adunblocker.com/server-tag.json') }}
</head>
<body>
  <h1>My Page</h1>
</body>
</html>

Custom Rendering

You can provide a custom callable to the render_script parameter to customize how script tags are rendered:
<!DOCTYPE html>
<html>
<head>
  <title>My Page</title>
  {{ server_tag('https://config.adunblocker.com/server-tag.json', 300, custom_renderer) }}
</head>
<body>
  <h1>My Page</h1>
</body>
</html>

Symfony Features

  • Twig Integration: Easy-to-use Twig function for templates
  • HTTP Client: Uses Symfony’s HTTP client for reliable requests
  • Caching: Built-in caching support with configurable TTL
  • Error Handling: Graceful error handling with fallback to empty arrays
  • Security: XSS protection with proper HTML escaping
  • Bundle Structure: Proper Symfony bundle with dependency injection

Symfony Requirements

  • PHP 7.4 or higher
  • Symfony 5.0, 6.0, or 7.0
  • Twig 2.0 or 3.0

Common Features

All PHP packages provide:
  • Remote Script Fetching: Fetch JavaScript files from external URLs
  • Caching Support: Built-in caching with configurable TTL
  • Error Handling: Graceful fallback when remote URLs are unavailable
  • Security: XSS protection with proper HTML escaping
  • Custom Rendering: Support for custom script tag rendering

Security Considerations

  • URL Validation: Only HTTP and HTTPS URLs are allowed
  • XSS Protection: All output is properly escaped
  • Error Handling: Failed requests don’t break page rendering
  • Caching: Reduces load on remote servers

Performance Tips

  1. Use Caching: Configure appropriate cache intervals for your use case
  2. Error Handling: Implement proper fallbacks for failed requests
  3. CDN Usage: Use CDN URLs for better performance
  4. Cache Warming: Pre-warm caches during deployment