Skip to content

Commit 6444871

Browse files
committed
Improve "Static files" section; add more information about public and webjars resources
1 parent 6f12049 commit 6444871

File tree

1 file changed

+32
-4
lines changed

1 file changed

+32
-4
lines changed

_posts/2015-03-17-static-files.md

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ For example:
1919

2020
```java
2121
Pippo pippo = new Pippo();
22-
pippo.addPublicResourceRoute();
23-
pippo.addWebjarsResourceRoute();
22+
pippo.addPublicResourceRoute(); "/public/..."
23+
pippo.addWebjarsResourceRoute(); "/webjars/..."
2424
```
2525

2626
or more verbose:
@@ -32,7 +32,7 @@ pippo.addResourceRoute(new WebjarsResourceHandler());
3232
```
3333

3434
You can use multiple `FileResourceRoute` but it is nonsense to use more `PublicResourceRoute` or more `WebjarsResourceRoute`.
35-
35+
3636
The [CrudNgDemo]({{ site.demourl }}/pippo-demo-crudng) (demo pippo-angularjs integration) is a good application that demonstrates the concept of static files.
3737
In `src/main/resources` we created a folder __public__ and we put all assets in that folder (imgs, css, js, fonts, ...).
3838

@@ -52,7 +52,7 @@ The CrudNgDemo uses the [Bootstrap](http://getbootstrap.com/) & [Font-Awesome](h
5252

5353
The CrudNgDemo also uses a custom CSS file which is a classpath resource from the `/public` folder.
5454

55-
In this demo, the html template page (freemarker engine) contains a head section like:
55+
In this demo, the html template page (`Freemarker engine`) contains a head section like:
5656

5757
```html
5858
<head>
@@ -92,6 +92,34 @@ Sure in your pom.xml file (if you use Maven) you must declare the dependencies t
9292
</dependency>
9393
```
9494

95+
Of course you can use `public` and `webjars` resources in your project without a template engine.
96+
In this case, your html file looks like
97+
98+
```html
99+
<!DOCTYPE html>
100+
<html>
101+
<head>
102+
<title>My web page</title>
103+
<meta charset="UTF-8">
104+
<meta name="viewport" content="width=device-width">
105+
106+
<link href="/webjars/bootstrap/css/bootstrap.min.css" rel="stylesheet">
107+
<link href="/webjars/font-awesome/css/font-awesome.min.css" rel="stylesheet">
108+
<link href="/public/css/style.css" rel="stylesheet">
109+
</head>
110+
111+
<body>
112+
<!-- My html content here --->
113+
114+
<script src="/webjars/jquery/jquery.min.js"></script>
115+
<script src="/webjars/bootstrap/js/bootstrap.min.js"></script>
116+
<script src="/public/js/app.js"></script>
117+
</body>
118+
</html>
119+
```
120+
121+
If you use a supported template engine, then you can use `publicAt` and `webjarsAt` functions.
122+
95123
If you want to serve static files that are not on the classpath then you may use the `FileResourceRoute`.
96124

97125
```java

0 commit comments

Comments
 (0)