Symfony Asset
Symfony component that generates and versions URLs for CSS, JavaScript, and image assets
Repository Health
Technical Analysis
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
Packagesservice that resolves asset paths against one or more namedPackageconfigurations - Pluggable versioning strategies (
EmptyVersionStrategy,StaticVersionStrategy, JSON-manifest-based versioning) for cache invalidation PathPackageandUrlPackageimplementations 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.
Used by 3 apps in this directory
Kimai
Invoicing Finance · Project Management
Professional open-source time tracking with invoicing, multi-user support, SAML/LDAP auth, and a full REST API—self-host it or use the cloud.
Mautic
Automation · Marketing · Ecommerce
The world's largest open source marketing automation platform — own your data, run multi-channel campaigns, and escape vendor lock-in forever.
wallabag
Bookmarks Archiving
Self-hosted read-it-later app that saves clean, ad-free articles from any webpage for distraction-free reading across all your devices.