Using Webjar to manage CSS, JavaScript files

Source: Internet
Author: User

The Web front end uses more and more JS or CSS, such as jquery, Backbone.js and Bootstrap. In general, we are copying these Web resources into the directory of Java, through manual management, this way easily lead to file confusion, version inconsistency and other issues.

Webjars is a jar package that packages these generic web front-end resources into Java, and then manages them with MAVEN tools to ensure that these Web resource versions are unique and easy to upgrade. About Webjars Resources, there is a dedicated website http://www.webjars.org/, we can go to this site to find their own resources, in their own projects to add to Maven dependency, you can directly use these resources.

In my project experiment, using SPINGMVC for front-end management, which used bootstrap as the skeleton of the foreground CSS, used the bootstrap resources of Webjars.

1, first in the project's pom dependency to add to the bootstrap Webjars dependency

<dependency>
<groupId>org.webjars</groupId>
<artifactId>bootstrap</artifactId>
<version>3.1.0</version>
</dependency>

2. In spring's configuration file, redirect access to/webjars to/meta-inf/resources/webjars/

<!--uses webjars so Javascript and CSS Libs can be declared as Maven dependencies (Bootstrap, jQuery ...)--
<mvc:resources mapping= "/webjars/**" location= "classpath:/meta-inf/resources/webjars/"/>

3, introduced in the page CSS, JS file, here is an inconvenient place to remember the version number

<link rel= 'stylesheet ' href='/webjars/bootstrap/3.1.0/css/bootstrap.min.css ' >

In Webjars's website, about three kinds of application webjars, respectively, NPM Webjars, Bower webjars, classic Webjars, my above method belongs to the classic Webjars way, the other two ways have not been applied , a follow-up study is needed .....

Using Webjar to manage CSS, JavaScript files

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.