Use webJar unified management of static resources

What is webjar?

webjar is the client (browser) resources (javascript, CSS, etc.) packaged into a jar file, for unified management of resources; webJar jar package deployed on the Maven central repository.

Why do we use webjar?

When we java web project development will use Maven, Gradle and other build tools to achieve the jar package version dependency management, and automated management of the project; but for javaScript, CSS resources of some front-end package, the past, we can only take the copy directly to the webapp manually in the directory, this approach can not be dependent on the management of these resources, container and cause the file to confusion, inconsistent versions of the problem; therefore, webjar developed which provides the front end to jar package in the form of our resources to facilitate our dependency management ;

webjar action principle

webJar is to package these generic web front-end resources into a jar package, and Maven tools help to manage; ensure the uniqueness of these versions of web resources, relatively easy to upgrade;

How to use WebJar

First, find the official website corresponding to the main components, such as jQuery; then add the appropriate dependencies;

<!--引入一个jQuery的jar包-->
        <dependency>
            <groupId>org.webjars</groupId>
            <artifactId>jquery</artifactId>
            <version>3.3.1</version>
        </dependency>

2. Next, we introduced a page;
<script th:src="@{/webjars/jquery/3.3.1/jquery.js}" </script>(Note: This depends on the particular path a position dependent resource package, below) Here Insert Picture Description
or more right we can use; like each of the above referenced document have a band version, if you want to upgrade the project, it is in trouble, so we add a version targeting tools;

<dependency>
     <groupId>org.webjars</groupId>
     <artifactId>webjars-locator-core</artifactId>
</dependency>

Then we can use <script th:src="@{/webjars/jquery/jquery.js}" </script>the page is introduced;

to sum up

What are the benefits of using WebJar front end dependence dependent unified management?
1, the use of WebJar approach to management, version solved the problem;
2, WebJar way to manage dependencies can bring to 2-5 times faster compilation speed of the project;

supplement:

We need to namespace template engine will be introduced prior to the introduction of the use of WebJar resource file:

<html xmlns:th="http://www.thymeleaf.org">

All of a sudden I fork out the original link, sorry ~ ~ ~

Published 31 original articles · won praise 11 · views 3730

Guess you like

Origin blog.csdn.net/z19950712/article/details/104354556