Static File’s Delivery
Framework provides flexible way to serve static files. It can be set of files from directory or individual file. Static section is optional one, for e.g: RESTful APIs typically this section is not needed. Static file(s) are delivered using http.ServeContent
.
Supported Features:
- Serve directory and it’s subtree files
- Serve individual file
- Directory listing
- HTTP Cache-Control: By
mime
types and defaults Since v0.6 - Cache Busting: By filename Since v0.7
Pick your choice of unique name
for each directory
or individual
file static route definition. It is called as route name
.
Static Routes Configuration
Section: static { … }
Use below config attributes to define your static routes in the routes.conf
.
path
Path config attribute is used to map the URL path of serving directory or individual file.
It is required, No default value.
dir
Dir config attribute is used to map the directory that will be served for mapped URL path.
It can be absolute directory path or relative path to application base directory.
No default value.
list
If you want to enable directory listing feature.
Default value is false
.
file
File config attribute is used to map individual file that will be served for mapped URL path.
It can be absolute directory path or relative to application base directory. If it’s relative path /static/
is prefixed automatically.
No default value.
Sample config for static section
Cache Control
Since v0.6 aah framework provides flexible way to configure static file Cache-Control
header by MIME
types. Default cache header is used if mime type is not configured.
Note: Cache configuration is in aah.conf
Sample Cache Configuration
Cache Busting
Since v0.7 aah provides simple filename Cache Busting
support.
Note: Upcoming feature
asset pipeline capability (such as minify, cache bust, update HTML template with minified version file and package after that).
How simple cache bust works?
Simple cache bust works with filename (prefix or suffix) using AppBuildInfo().Version
value.
- Prefix:
813e524-aah.css
or - Suffix:
aah-813e524.css
Typically you choose/select files for Cache Busting
.