Symfony Asset

Symfony component that generates and versions URLs for CSS, JavaScript, and image assets

Library
Composer
vv8.1.0
3,148stars
MIT License

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum.How we score it →
72/100Good
Development Activity68
Maintenance68
Community52
Maturity60
Momentum40

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation.How we score it →
71/100Good
Architecture76
Code Quality78
Innovation55
Learning Curve75

The Symfony Asset component centralizes how an application builds URLs for its static assets — stylesheets, scripts, images — so templates never hardcode base paths or cache-busting query strings by hand. It supports multiple named asset packages (e.g. serving some assets from a CDN and others locally), versioning strategies for cache invalidation, and context-aware path generation that respects the current request’s base path and protocol.

As one of Symfony’s small, focused components, it can be used standalone in any PHP project or, more commonly, through the full-stack framework’s asset() Twig function and Packages service, where it plugs into asset-mapper or Webpack Encore output without applications needing to reimplement URL-versioning logic themselves.

What You Get

  • A Packages service that resolves asset paths against one or more named Package configurations
  • Pluggable versioning strategies (EmptyVersionStrategy, StaticVersionStrategy, JSON-manifest-based versioning) for cache invalidation
  • PathPackage and UrlPackage implementations for local base-path or absolute CDN-URL asset serving
  • Request-context awareness so generated URLs respect the current base path, scheme, and host
  • A small, dependency-light API usable outside the full Symfony framework

Common Use Cases

  • Serving static assets from a CDN in production while falling back to local paths in development, from the same template code
  • Busting browser caches automatically after a deploy via manifest-based or static versioning strategies
  • Generating asset URLs correctly under a subdirectory-mounted application without hardcoding the base path
  • Standardizing asset URL generation across multiple bundles/modules in a large Symfony application

Under The Hood

Architecture The component centers on Packages.php, a registry of named PackageInterface implementations; PathPackage and UrlPackage compose a VersionStrategy (under VersionStrategy/) with the current Context (request base path/host) to produce a final versioned URL string — a small, composable strategy-pattern design with no hidden global state.

Tech Stack Minimal pure-PHP component requiring only PHP 8.4+, with symfony/http-client, symfony/http-foundation, and symfony/http-kernel as dev-only dependencies used for optional request-context integration and testing — the runtime dependency footprint is effectively zero.

Code Quality The Tests/ directory mirrors the small source tree (Package, VersionStrategy, Context) with PHPUnit tests for each strategy and edge cases like absolute URLs and base-path handling; the component’s narrow scope keeps the test surface manageable and thorough.

API Design The public API is small and consistent — instantiate a Package with a version strategy, call getUrl() — mirroring the ergonomics of Symfony’s other micro-components; it is one of the easier Symfony components to learn in isolation given its single responsibility.

Join founders buildingwith open source

Opinionated takes, migration guides, cost-saving tips, and insights from the open source ecosystem.

Subscribe on Substack
Join 750+ subscribers

Search