Webjars support
This feature enable serving static content provided by webjars. It allows you to package your assets suchas javascript libraries and css as part of your uber-jar.
Installing the feature
install(Webjars) {
path = "assets" //defaults to /webjars
zone = ZoneId.of("EST") //defaults to ZoneId.systemDefault()
}
This configures the feature to serve any webjars assets on the /assets/
path. The zone
argument configures the correct time zone tobe used with the Last-Modified
header to support caching (only if Conditional Headers feature is also installed).
This feature is defined in the class io.ktor.Webjars
in the artifact io.ktor:ktor-webjars:$ktor_version
.
dependencies { implementation "io.ktor:ktor-webjars:$ktor_version"}
dependencies { implementation("io.ktor:ktor-webjars:$ktor_version")}
<project> … <dependencies> <dependency> <groupId>io.ktor</groupId> <artifactId>ktor-webjars</artifactId> <version>${ktor.version}</version> <scope>compile</scope> </dependency> </dependencies></project>
Versioning support
Webjars allow developers to change the versions of the dependencies without requiring a change on the path used to load them on your templates.
Let’s assume you have imported org.webjars:jquery:3.2.1
, you can use the following html code to import it:
<head>
<script src="/webjars/jquery/jquery.js"></script>
</head>
You don’t need to specify a version, should you choose to update your dependencies you don’t need to modify your templates.