Class LastModifiedServlet

  • All Implemented Interfaces:
    Serializable, Servlet, ServletConfig

    public class LastModifiedServlet
    extends HttpServlet
    Sets the modified time to that of the file itself and all dependencies. Currently only *.css supported.

    When mapped to handle *.css files, parses the underlying file from the web resources and automatically adds lastModified=#### URL parameters. This allows the replacement of files to be immediately visible to browsers while still efficiently caching when nothing changed.

    The current CSS parser is extremely simple and may not catch all URLs. Specifically, it only looks for URLs on a line-by-line basis and does not support backslash (\) escapes. (TODO: Are backslash escapes even part of CSS?)

    TODO: Handle escapes, which might require a parser more complicated than this regular expression, including escaped quotes in quotes, or escaped parenthesis: https://developer.mozilla.org/en-US/docs/Web/CSS/url(), https://stackoverflow.com/questions/25613552/how-should-i-escape-image-urls-for-css.

    All files must be in the StandardCharsets.UTF_8 encoding.

    TODO: Add support for non-url imports TODO: Review recursive import url(...) works correctly (urls within the included urls should be applied)

    TODO: Rewrite all URLs to be app-relative, with contextPath prefixed, much like how other URLs are rewritten. This is so paths will still be relative to the CSS file even when included into a page directly.

    See Also:
    This requires the cache be active, Serialized Form