Take a look at the webjars-locator project, you can use it to create the right query controller.
In case of using Spring MVC it will be:
@ResponseBody @RequestMapping("/webjarslocator/{webjar}/**") public ResponseEntity locateWebjarAsset(@PathVariable String webjar, HttpServletRequest request) { try { String mvcPrefix = "/webjarslocator/" + webjar + "/"; // This prefix must match the mapping path! String mvcPath = (String) request.getAttribute(HandlerMapping.PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE); String fullPath = assetLocator.getFullPath(webjar, mvcPath.substring(mvcPrefix.length())); return new ResponseEntity(new ClassPathResource(fullPath), HttpStatus.OK); } catch (Exception e) { return new ResponseEntity<>(HttpStatus.NOT_FOUND); } }
Disclaimer: This is the code from the WebJars documentation (section Making dependencies version agnostic ).
In this case, you can request js libraries as follows:
<link rel='stylesheet' href='/webjarslocator/bootstrap/css/bootstrap.min.css'>
Please note that there is no version in this URL.
You can also try to optimize these requests (and therefore scan the file system) using the cache, but I'm pretty sure that some kind of cache is already involved in the webjars-locator (I did not check this).
source share