Static Resources
SeedStack provides static resource serving from the classpath and the document root with some benefits over the container default resource serving:
- Automatic serving of pre-minified and/or pre-gzipped versions of resources,
- On-the-fly gzipping of resources,
- Cache friendly.
Behavior
The behavior is to serve resources located under the document root folder and, if not found, under the META-INF/resources
classpath location on the /*
path. For example, consider the following folder tree:
src/main/webapp
index.html
robots.txt
META-INF
resources
robots.txt
lib
jquery.js
jquery.min.js
jquery.min.js.gz
The default behavior is to serve index.html, robots.txt and jquery.js on the following paths:
/robots.txt
/index.html
/lib/jquery.js
The jquery.js file will be served as a minified and gzipped version (without the overhead of on-the-fly gzipping since a pre-gzipped version is already available).
Static resource serving is enabled by default. Resources from document root are always served in priority over classpath resources.
Configuration
web:
static:
# If true, static resource serving is enabled
enabled: (boolean)
# If true, minification support is enabled, serving *.min files instead of regular ones if possible
minification: (boolean)
# If true, gzip support is enabled, serving *.gz files instead of regular ones if possible
gzip: (boolean)
# If true, resources are gzipped on the fly, unless an already gzipped version (*.gz) exists
gzipOnTheFly: (boolean)
# The size of the buffer used for send static resource data
bufferSize: (int)
To dump the web.static
configuration options:
mvn -q -Dargs="web.static" seedstack:config
MIME types
The following MIME types are automatically derived from extensions:
Mime type | Extensions |
---|---|
text/html | html htm HTML HTM |
text/plain | txt text TXT TEXT |
text/javascript | js JS |
text/css | css less CSS LESS |
image/gif | gif GIF |
image/jpeg | jpeg jpg jpe JPEG JPG JPE |
image/png | png PNG |
image/vnd.microsoft.icon | ico ICO |
application/pdf | pdf PDF |
application/json | json JSON |
application/font-woff | woff WOFF |
application/vnd.ms-fontobject | eot EOT |
font/truetype | ttf TTF |
font/opentype | otf OTF |
Caching
Resource lookup mechanism try to find resources in the following order:
- Gzipped minified version,
- Gzipped version,
- Minified version,
- Normal version.
Once a resource is found, its metadata (but not the contents) is cached to avoid unnecessary lookup. This cache can be configured as below:
web:
static:
cache:
# Maximum concurrent cache updates allowed
concurrencyLevel: (int)
# Maximum number of cache entries
maxSize: (int)
# Initial number of cache entries
initialSize: (int)
To dump the web.static.cache
configuration options:
mvn -q -Dargs="web.static.cache" seedstack:config