• A Package for Balancing Static File Requests

    A parcel conveyor splits into three tracks leading to separate loading doors in a stone courtyard

    URL Balancer chooses a domain for a static asset URL. It was intended for sites serving static files without a CDN: in HTTP/1.x, spreading requests across hostnames could let browsers open more connections and download more assets in parallel.

    The package supported Composer installation, Silex integration and extensible balancing strategies. It only constructs URLs. Each configured domain must already serve the corresponding files; the library does not distribute the files or act as a network load balancer.

    Original Composer setup

    The original example pinned version 1.1.2:

    json
    {
      "require": {
        "astartsky/url-balancer": "1.1.2"
      }
    }

    Usage example

    Configure a strategy and add the domains that serve your static files:

    php
    $urlBalancer = new \Astartsky\UrlBalancer\UrlBalancer();
    $urlBalancer->setStrategy(new \Astartsky\UrlBalancer\Strategy\HashStrategy());
    $urlBalancer->addBucket(new \Astartsky\UrlBalancer\Domain("s1.myawesomesite.com"));
    $urlBalancer->addBucket(new \Astartsky\UrlBalancer\Domain("s2.myawesomesite.com"));
    $urlBalancer->addBucket(new \Astartsky\UrlBalancer\Domain("s3.myawesomesite.com"));
    
    $url = $urlBalancer->getUrl("/images/my_impressive_content.png");

    The example uses the hash strategy to choose a domain for the image path. The API is documented in the package README on Packagist, and the source repository preserves the implementation.

    Why this stays in the archive

    Domain sharding addressed a connection limit in HTTP/1.x. With HTTP/2, multiple requests can share a connection, so opening connections to extra hostnames can add overhead instead of removing a bottleneck. Cloudflare’s HTTP/2 guide for web developers explains why this changed the old optimization advice.

    For a current site, check the protocol actually used to deliver its assets and measure the bottleneck before adding domains. Splitting URLs across hosts does not by itself make delivery faster.