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 typeExtensions
text/htmlhtml htm HTML HTM
text/plaintxt text TXT TEXT
text/javascriptjs JS
text/csscss less CSS LESS
image/gifgif GIF
image/jpegjpeg jpg jpe JPEG JPG JPE
image/pngpng PNG
image/vnd.microsoft.iconico ICO
application/pdfpdf PDF
application/jsonjson JSON
application/font-woffwoff WOFF
application/vnd.ms-fontobjecteot EOT
font/truetypettf TTF
font/opentypeotf OTF

Caching

Resource lookup mechanism try to find resources in the following order:

  1. Gzipped minified version,
  2. Gzipped version,
  3. Minified version,
  4. 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

   

On this page


Edit