Static Assets
Framefox provides a robust system for managing static assets like CSS files, JavaScript, images, fonts, and other files that don’t change during runtime. Theasset() function handles asset URLs with automatic versioning for cache management.
Static File Location
All static assets are stored in thepublic/ directory of your project:
The asset() Function
Theasset() function generates URLs for static files with automatic versioning.
Syntax
Parameters
- path (str): Path relative to the
public/directory - versioning (bool, optional): Enable/disable versioning (default:
True)
How It Works
- Takes a file path relative to
public/ - Generates the full URL using the
base_urlsetting - Adds a version query parameter based on file modification time
- Returns the complete URL
CSS Assets
Loading Stylesheets
Page-Specific Stylesheets
Organizing CSS Files
JavaScript Assets
Loading Scripts
Page-Specific JavaScript
Organizing JavaScript Files
Image Assets
Basic Images
Responsive Images
Background Images in CSS
In your CSS files, use relative paths:Dynamic User Images
Other Asset Types
Fonts
Downloadable Files
Favicons
Asset Versioning
Automatic Cache Busting
When versioning is enabled (default), asset URLs include a version parameter:How Versioning Works
-
File exists: MD5 hash of modification timestamp
-
File not found: Current timestamp
Disabling Versioning
- External CDN assets
- Files that should never cache-bust
- Development/testing scenarios
Benefits of Versioning
- Automatic updates: Browsers fetch new versions when files change
- Optimal caching: Unchanged files remain cached
- No manual intervention: Version updates automatically
- CDN compatible: Works with content delivery networks
Configuration
Configure asset settings inconfig/settings.yaml:
Best Practices
1. Organize Assets by Type
2. Use Descriptive Names
3. Optimize Images
- Use appropriate formats (JPEG for photos, PNG for graphics, SVG for icons)
- Compress images before deployment
- Consider using responsive images for different screen sizes
4. Minimize HTTP Requests
5. Load Scripts at the End
6. Use CDNs for Popular Libraries
Complete Example
Next Steps
- Learn about template functions
- Explore template inheritance
- Read the template overview