In this article, we are going to present several ways to add Bootstrap library to the Thymeleaf project. We will include Bootstrap assets using static resources, content delivery network, and webjar libraries.
2. Add Bootstrap using WebJars
WebJars are front-end libraries packed into Java Archive files (JAR). They allow us to use project build tools like Maven or Gradle to download client-side dependencies just like any other external libraries.
3. Adding Bootstrap library using static asset files
Let's take a look at another way to add the Bootstrap library to the Thymeleaf template.
In this example we used Bootstrap CSS and JS files included in Spring Boot default static resources directory in the organized in the following structure:
4. Add Bootstrap using CDN
Content Delivery Network is a distributed system whose main task is to provide content in the shortest possible time to which many users from different places have access.
Bootstrap, jQuery, and many other popular libraries can be included in the website using CDN links.
In the following example we present how to ue CDN to include Bootstrap in Thymeleaf template:
In this article, we presented several ways to include the Bootstrap library in Thymeleaf template. Which method is better for your project depends on many factors. For those who don't like external links on their pages, we recommend WebJars or even static files included in the project structure. For those who want to speed up resources uploading time, we will recommend CDN.