fonts and styles are now cachable - fixes #286

Sun, 03 Sep 2023 12:02:44 +0200

author
Mike Becker <universe@uap-core.de>
date
Sun, 03 Sep 2023 12:02:44 +0200
changeset 289
d702bdd4da51
parent 288
10324c383126
child 290
51b14787d826

fonts and styles are now cachable - fixes #286

build.gradle.kts file | annotate | diff | comparison | revisions
src/main/kotlin/de/uapcore/lightpit/filter/StaticFilesFilter.kt file | annotate | diff | comparison | revisions
src/main/webapp/WEB-INF/changelogs/changelog-de.jspf file | annotate | diff | comparison | revisions
src/main/webapp/WEB-INF/changelogs/changelog.jspf file | annotate | diff | comparison | revisions
src/main/webapp/WEB-INF/jsp/site.jsp file | annotate | diff | comparison | revisions
     1.1 --- a/build.gradle.kts	Tue Jul 25 18:19:04 2023 +0200
     1.2 +++ b/build.gradle.kts	Sun Sep 03 12:02:44 2023 +0200
     1.3 @@ -5,7 +5,7 @@
     1.4      war
     1.5  }
     1.6  group = "de.uapcore"
     1.7 -version = "1.1.1"
     1.8 +version = "1.1.2"
     1.9  
    1.10  repositories {
    1.11      mavenCentral()
    1.12 @@ -53,7 +53,7 @@
    1.13          val test by getting {
    1.14              dependencies {
    1.15                  implementation("org.jetbrains.kotlin:kotlin-test-junit5")
    1.16 -                runtimeOnly("org.junit.jupiter:junit-jupiter-engine:5.5.2")
    1.17 +                runtimeOnly("org.junit.jupiter:junit-jupiter-engine:5.10.0")
    1.18              }
    1.19          }
    1.20      }
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/src/main/kotlin/de/uapcore/lightpit/filter/StaticFilesFilter.kt	Sun Sep 03 12:02:44 2023 +0200
     2.3 @@ -0,0 +1,41 @@
     2.4 +import jakarta.servlet.FilterChain
     2.5 +import jakarta.servlet.annotation.WebFilter
     2.6 +import jakarta.servlet.http.HttpFilter
     2.7 +import jakarta.servlet.http.HttpServletRequest
     2.8 +import jakarta.servlet.http.HttpServletResponse
     2.9 +
    2.10 +/*
    2.11 + * Copyright 2023 Mike Becker. All rights reserved.
    2.12 + *
    2.13 + * Redistribution and use in source and binary forms, with or without
    2.14 + * modification, are permitted provided that the following conditions are met:
    2.15 + *
    2.16 + * 1. Redistributions of source code must retain the above copyright
    2.17 + * notice, this list of conditions and the following disclaimer.
    2.18 + *
    2.19 + * 2. Redistributions in binary form must reproduce the above copyright
    2.20 + * notice, this list of conditions and the following disclaimer in the
    2.21 + * documentation and/or other materials provided with the distribution.
    2.22 + *
    2.23 + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
    2.24 + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
    2.25 + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
    2.26 + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
    2.27 + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
    2.28 + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
    2.29 + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
    2.30 + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
    2.31 + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
    2.32 + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    2.33 + */
    2.34 +
    2.35 +@WebFilter(urlPatterns = ["*.ttf", "*.css", "*.js"])
    2.36 +class StaticFilesFilter : HttpFilter() {
    2.37 +    override fun doFilter(req: HttpServletRequest, res: HttpServletResponse, chain: FilterChain) {
    2.38 +        // Apply a Cache-Control Header for static files to allow storing them
    2.39 +        // in shared cache for almost indefinitely. We will cache-bust them when we need an update.
    2.40 +        // RFC-2616 mandates that servers SHOULD NOT specify more than one year, though
    2.41 +        res.addHeader("Cache-Control", "public, max-age=31536000, immutable")
    2.42 +        super.doFilter(req, res, chain)
    2.43 +    }
    2.44 +}
     3.1 --- a/src/main/webapp/WEB-INF/changelogs/changelog-de.jspf	Tue Jul 25 18:19:04 2023 +0200
     3.2 +++ b/src/main/webapp/WEB-INF/changelogs/changelog-de.jspf	Sun Sep 03 12:02:44 2023 +0200
     3.3 @@ -24,6 +24,14 @@
     3.4    --%>
     3.5  <%@ page contentType="text/html;charset=UTF-8" %>
     3.6  
     3.7 +<h3>Version 1.1.2</h3>
     3.8 +
     3.9 +<ul>
    3.10 +    <li>
    3.11 +        Schriftarten und Styles können nun vom Browser im Cache gespeichert werden.
    3.12 +    </li>
    3.13 +</ul>
    3.14 +
    3.15  <h3>Version 1.1.1</h3>
    3.16  
    3.17  <ul>
     4.1 --- a/src/main/webapp/WEB-INF/changelogs/changelog.jspf	Tue Jul 25 18:19:04 2023 +0200
     4.2 +++ b/src/main/webapp/WEB-INF/changelogs/changelog.jspf	Sun Sep 03 12:02:44 2023 +0200
     4.3 @@ -24,6 +24,14 @@
     4.4    --%>
     4.5  <%@ page contentType="text/html;charset=UTF-8" %>
     4.6  
     4.7 +<h3>Version 1.1.2</h3>
     4.8 +
     4.9 +<ul>
    4.10 +    <li>
    4.11 +        Fix that browsers could not store fonts and stylesheets in cache.
    4.12 +    </li>
    4.13 +</ul>
    4.14 +
    4.15  <h3>Version 1.1.1</h3>
    4.16  
    4.17  <ul>
     5.1 --- a/src/main/webapp/WEB-INF/jsp/site.jsp	Tue Jul 25 18:19:04 2023 +0200
     5.2 +++ b/src/main/webapp/WEB-INF/jsp/site.jsp	Sun Sep 03 12:02:44 2023 +0200
     5.3 @@ -31,7 +31,7 @@
     5.4  <%@taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
     5.5  
     5.6  <%-- Version suffix for forcing browsers to update the CSS / JS files --%>
     5.7 -<c:set scope="page" var="versionSuffix" value="20230108"/>
     5.8 +<c:set scope="page" var="versionSuffix" value="20230903"/>
     5.9  
    5.10  <%-- Make the base href easily available at request scope --%>
    5.11  <c:set scope="page" var="baseHref" value="${requestScope[Constants.REQ_ATTR_BASE_HREF]}"/>

mercurial