AssetManager class manages the generation and serving of Flux CSS and JavaScript assets. It handles both development and production builds, asset versioning, and CSP nonce support.
Overview
The AssetManager is primarily used internally by Flux, but its static methods can be accessed directly:Methods
boot()
Bootstrap the AssetManager.scripts()
Generate the Flux JavaScript script tag.Configuration optionsOptions:
nonce(string): CSP nonce value for the script tag
- In production (
app.debug = false): Serves minified version (flux.min.js) - In development (
app.debug = true): Serves unminified version (flux.js) - Automatically detects Flux Pro vs Flux Lite
- Includes
data-navigate-onceattribute for Livewire navigation - Adds version hash for cache busting
fluxAppearance()
Generate inline styles and scripts for dark mode support.Configuration optionsOptions:
nonce(string): CSP nonce value for inline style and script tags
- Sets
color-scheme: darkin dark mode for proper scrollbar styling - Provides
window.Flux.applyAppearance()function - Supports three appearance modes:
'light','dark','system' - Persists preference to
localStorage(except for system mode) - Applies stored preference on page load to prevent flash
editorStyles()
Generate the Flux editor CSS link tag (Flux Pro only).\Exception if Flux Pro is not installed
Example:
editorScripts()
Generate the Flux editor JavaScript script tag (Flux Pro only).defer attribute
Throws: \Exception if Flux Pro is not installed
Behavior:
- In production: Serves
editor.min.js - In development: Serves
editor.js - Includes version hash for cache busting
Asset Routes
The AssetManager registers the following routes:| Route | Description | Handler |
|---|---|---|
/flux/flux.js | Development JavaScript | fluxJs() |
/flux/flux.min.js | Production JavaScript | fluxMinJs() |
/flux/editor.css | Editor CSS (Pro only) | editorCss() |
/flux/editor.js | Editor JavaScript (Pro only) | editorJs() |
/flux/editor.min.js | Editor JavaScript minified (Pro only) | editorMinJs() |
Route Handlers
fluxJs()
Serve the development Flux JavaScript.fluxMinJs()
Serve the production (minified) Flux JavaScript.editorCss()
Serve the Flux editor CSS.\Exception if Flux Pro is not installed
editorJs()
Serve the development Flux editor JavaScript.\Exception if Flux Pro is not installed
editorMinJs()
Serve the production (minified) Flux editor JavaScript.\Exception if Flux Pro is not installed
Blade Directives
The AssetManager registers two Blade directives:@fluxScripts
Render the Flux JavaScript assets.@fluxAppearance
Render the Flux appearance management scripts.Caching
All asset responses include aggressive caching headers:- Cache-Control:
public, max-age=31536000(1 year) - Expires: 1 year from request time
- Last-Modified: File modification timestamp
- 304 Not Modified: Returned when
If-Modified-Sincematches
Version Hashing
Assets use version hashes from the manifest file for cache busting:Content Security Policy (CSP)
All asset generation methods support CSP nonces:Examples
Basic Layout
With CSP Nonces
Flux Pro Editor
Related
- Flux Facade - Access AssetManager methods via facade
- FluxManager - Core manager that uses AssetManager
- Blade Directives - Blade directive documentation