WebJars是打包到JAR(Java Archive)文件中的客户端Web库(例如jQuery和Bootstrap)。
- 在基于JVM的Web应用程序中显式轻松地管理客户端依赖项
- 使用基于JVM的构建工具(例如Maven,Gradle,sbt,...)来下载客户端依赖项
- 了解您正在使用的客户端依赖项
- 传递依赖关系会自动解析,并可选择通过RequireJS加载
- 部署在Maven Central上
- 公共CDN,慷慨提供:
-
Pom.xml
<!-- https://mvnrepository.com/artifact/org.webjars/webjars-locator --> <dependency> <groupId>org.webjars</groupId> <artifactId>webjars-locator</artifactId> <version>0.32-1</version> </dependency> <dependency> <groupId>org.webjars</groupId> <artifactId>bootstrap</artifactId> <version>3.3.7-1</version> </dependency> <dependency> <groupId>org.webjars</groupId> <artifactId>jquery</artifactId> <version>3.2.1</version> </dependency>
- webjars-locator 包的作用是省略 webjar 的版本。比如对于请求
http://localhost:8080/webjars/jquery/3.1.0/jquery.js
省略版本号 3.2.1 直接使用http://localhost:8080/webjars/jquery/jquery.js
也可访问。
- webjars-locator 包的作用是省略 webjar 的版本。比如对于请求
-
Html 页面引用资源文件
原:
<link rel="stylesheet" href="/css/bootstrap.min.css"/>
现:
<link rel="stylesheet" href="/webjars/bootstrap/css/bootstrap.min.css"/>
-
其他资源文件引用方式:cdn加速服务
<link href="https://cdn.bootcss.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet">