Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit76e6ea3

Browse files
committed
Refactor static assets for better caching / fingerprinting
1 parent8a6d2f8 commit76e6ea3

File tree

11 files changed

+52
-21
lines changed

11 files changed

+52
-21
lines changed

‎stubbornjava-common/src/main/java/com/stubbornjava/common/undertow/handlers/CustomHandlers.java‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
importjava.io.File;
55
importjava.nio.file.Paths;
66
importjava.util.SortedMap;
7-
importjava.util.concurrent.TimeUnit;
87

98
importorg.slf4j.Logger;
109
importorg.slf4j.LoggerFactory;
@@ -57,7 +56,7 @@ public static HttpHandler gzip(HttpHandler next) {
5756
.setNext(next);
5857
}
5958

60-
publicstaticHttpHandlerresource(Stringprefix) {
59+
publicstaticHttpHandlerresource(Stringprefix,intcacheTime) {
6160
ResourceManagerresourceManager =null;
6261
if (Env.LOCAL ==Env.get()) {
6362
Stringpath =Paths.get(AssetsConfig.assetsRoot(),prefix).toString();
@@ -68,7 +67,7 @@ public static HttpHandler resource(String prefix) {
6867
resourceManager =newClassPathResourceManager(CustomHandlers.class.getClassLoader(),prefix);
6968
}
7069
ResourceHandlerhandler =newResourceHandler(resourceManager);
71-
handler.setCacheTime((int)TimeUnit.HOURS.toSeconds(4));
70+
handler.setCacheTime(cacheTime);
7271
returnhandler;
7372
}
7473

‎stubbornjava-webapp/src/main/java/com/stubbornjava/webapp/StubbornJavaWebApp.java‎

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
importstaticcom.stubbornjava.common.undertow.handlers.CustomHandlers.timed;
44

5+
importjava.util.concurrent.TimeUnit;
6+
57
importorg.slf4j.Logger;
68
importorg.slf4j.LoggerFactory;
79

@@ -43,7 +45,7 @@ private static HttpHandler wrapWithMiddleware(HttpHandler handler) {
4345
.get("/",timed("getHome",PageRoutes::home))
4446
.get("/ping",timed("ping",PageRoutes::ping))
4547

46-
.get("/favicon.ico",timed("favicon",CustomHandlers.resource("images/")))
48+
.get("/favicon.ico",timed("favicon",CustomHandlers.resource("images/", (int)TimeUnit.DAYS.toSeconds(30))))
4749
.get("robots.txt",timed("robots",PageRoutes::robots))
4850

4951
.get("/posts/{slug}",timed("getPost",PostRoutes::getPost))
@@ -67,10 +69,7 @@ private static HttpHandler wrapWithMiddleware(HttpHandler handler) {
6769
;
6870

6971
privatestaticfinalHttpHandlerstaticRoutes =newPathHandler(basicRoutes)
70-
.addPrefixPath("/css",timed("getCss",CustomHandlers.resource("css/")))
71-
.addPrefixPath("/js",timed("getJs",CustomHandlers.resource("js/")))
72-
.addPrefixPath("/assets/fonts",timed("getJs",CustomHandlers.resource("fonts/")))
73-
.addPrefixPath("/images",timed("getImages",CustomHandlers.resource("images/")))
72+
.addPrefixPath("/assets",timed("getAssets",CustomHandlers.resource("", (int)TimeUnit.DAYS.toSeconds(30))))
7473
;
7574

7675
privatestaticvoidstartServer() {

‎stubbornjava-webapp/src/main/resources/application.conf‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
assets.root = "ui/assets"
2+
13
db {
24
url="jdbc:mysql://localhost:3306/stubbornjava"
35
driver="com.mysql.jdbc.Driver"

‎stubbornjava-webapp/ui/package.json‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
"style-loader":"^0.13.1",
3131
"url-loader":"^0.5.7",
3232
"webpack":"^2.2.1",
33+
"webpack-clean-obsolete-chunks":"^0.3.0",
3334
"webpack-config":"^7.0.0"
3435
},
3536
"scripts": {}

‎stubbornjava-webapp/ui/src/common/head.hbs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@
33
<metahttp-equiv="x-ua-compatible"content="ie=edge"/>
44
<metaname="description"content="{{#ifmetaDesc}}{{metaDesc}}{{/if}}"/>
55
{{!-- <link rel="stylesheet" href="/css/3rdparty.css"/>--}}
6-
<linkrel="stylesheet"href="/css/common.css"/>
6+
<linkrel="stylesheet"href="/assets/css/common.css"/>
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
{{!-- <script async type="text/javascript" src="/js/3rdparty.js"></script> --}}
22
{{!-- Making this script async breaks the jump to id functionality :( --}}
3-
<scripttype="text/javascript"src="/js/common.js"></script>
3+
<scripttype="text/javascript"src="/assets/js/common.js"></script>

‎stubbornjava-webapp/ui/src/posts/webpack-and-npm-for-simple-java-8-web-apps.hbs‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,22 +44,22 @@
4444
<p>You should be able to clone the repo and run the <code>WebpackServer</code> example. As long as you run <code>webpack --progress --watch</code> everything should work locally. If there are issues loading assets try changing the <code>assets.root</code> property found <ahref="https://github.com/StubbornJava/StubbornJava/blob/master/stubbornjava-examples/src/main/resources/application.conf#L2">here</a>. This is a hack to make files load faster in the IDE, for some reason even with native hooks turned on the IDE's are slow to pick up file changes. Here are screen shots of the four pages. If you are not a strong HTML / CSS developer consider using a <ahref="/best-selling-html-css-themes-and-website-templates">site template</a> to make your website stand out.</p>
4545

4646
<h2class="anchored">home</h2>
47-
<div><imgwidth=100%src="/images/homepage.png" /></div>
47+
<div><imgwidth=100%src="/assets/images/homepage.png" /></div>
4848
<hr/>
4949
<br/>
5050
<br/>
5151
<br/>
5252
<h2class="anchored">hello {name}</h2>
53-
<imgwidth=100%src="/images/hello.png" />
53+
<imgwidth=100%src="/assets/images/hello.png" />
5454
<hr/>
5555
<br/>
5656
<br/>
5757
<br/>
5858
<h2class="anchored">Not Found</h2>
59-
<imgwidth=100%src="/images/notfound.png" />
59+
<imgwidth=100%src="/assets/images/notfound.png" />
6060
<hr/>
6161
<br/>
6262
<br/>
6363
<br/>
6464
<h2class="anchored">Server Error</h2>
65-
<imgwidth=100%src="/images/error.png" />
65+
<imgwidth=100%src="/assets/images/error.png" />
17.8 KB
Loading

‎stubbornjava-webapp/ui/src/widgets/nav/header.hbs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<navclass="navbar navbar-inverse navbar-expand fixed-top"role="navigation">
22
<aclass="navbar-brand logo"href="/">
3-
<spanclass="align-middle"><imgsrc="/images/PenguinHQ.png"height="40px"> Stubborn<spanclass="java">Java</span></span>
3+
<spanclass="align-middle"><imgsrc="/assets/images/PenguinHQ.png"height="40px"> Stubborn<spanclass="java">Java</span></span>
44
{{!-- Add this SVG instead later. I can't get CSS to work --}}
55
{{!-- <span>{{> templates/src/widgets/nav/logo }} Stubborn<span class="java">Java</span></span> --}}
66
</a>

‎stubbornjava-webapp/ui/src/widgets/social/twitter/summary-card.hbs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22
<metaname="twitter:site"content="@StubbornJava" />
33
<metaname="twitter:title"content="{{title}}" />
44
<metaname="twitter:description"content="{{desc}}" />
5-
<metaname="twitter:image"content="/images/PenguinHQ.png" />
5+
<metaname="twitter:image"content="https://www.stubbornjava.com/assets/images/PenguinHQ_compressed.png" />

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp