- Can I use nette/assets in Laravel even though it’s designed for Nette?
- Yes, nette/assets works well with Laravel for static assets like CSS, JS, and fonts. Its core features—versioning, caching, and URL generation—align with Laravel’s needs. You’ll need to manually bridge it with Laravel’s service container or use a facade for Blade templates, but the architecture is compatible.
- How do I integrate nette/assets with Laravel’s Blade templates?
- Use a custom Blade directive or a service method to generate asset URLs. For example, register a helper like `asset()` or `@asset()` in your `AppServiceProvider` to wrap nette/assets’ `AssetManager`. This lets you replace hardcoded paths (e.g., `/css/main.css`) with dynamic, versioned URLs.
- Does nette/assets support Laravel Mix or Vite for asset bundling?
- nette/assets isn’t a replacement for Mix/Vite but can work alongside them. Register your Mix/Vite build output directory (e.g., `public/build`) with `addDirectory()`, and use `ViteMapper` for dev server proxying. However, you’ll need to manually sync hashes between Vite’s manifest and nette/assets’ versioning.
- How do I disable versioning in development but enable it in production?
- Configure versioning per environment in your `AppServiceProvider`. Use `setTemporary()` or environment checks to disable versioning in development while enabling file-based or global versioning in production. This avoids cache-busting overhead during development.
- Will nette/assets improve my Core Web Vitals scores?
- Yes, nette/assets helps by enabling WOFF2 font support, automatic cache-busting, and proper `crossorigin` attributes for fonts. These features directly address LCP (Largest Contentful Paint) and reduce render-blocking. Pair it with Laravel’s HTTP caching for optimal performance.
- Can I use nette/assets for dynamic assets like user-uploaded files?
- nette/assets is designed for static assets and doesn’t natively support dynamic files. For user uploads, you’d need to implement a custom `IStorage` adapter or handle paths manually. It’s better suited for CSS, JS, and pre-defined assets.
- How do I handle asset hashes when using Vite’s manifest.json?
- Manually parse Vite’s `manifest.json` to extract hashes, then register those files with nette/assets using `addFile()`. Alternatively, disable nette/assets’ versioning and rely on Vite’s built-in hashing. This requires custom logic but ensures consistency between build tools.
- What Laravel versions does nette/assets support?
- nette/assets itself has no Laravel-specific dependencies, but its integration requires PHP 8.0+ and Laravel 8+. Test compatibility with your Laravel version by checking for PSR-4 autoloading conflicts and Blade directive syntax. The package’s core logic is version-agnostic.
- Are there alternatives to nette/assets for Laravel?
- Yes, Laravel has built-in asset helpers (`asset()`, `mix()`) and packages like `laravel-mix` or `vite-laravel`. For versioning and caching, consider `spatie/laravel-assets` or `filp/whoops` for error pages. nette/assets stands out for its lightweight, Nette-inspired API and Core Web Vitals optimizations.
- How do I test nette/assets in a Laravel CI pipeline?
- Test by verifying asset URLs in Blade templates and checking versioned paths in production-like environments. Use Laravel’s `Http` tests to assert responses include correct cache headers and hashes. Mock the `AssetManager` in unit tests to isolate logic from file system dependencies.