Home > Blockchain >  How to access JS file from within template html page? Spring Boot
How to access JS file from within template html page? Spring Boot

Time:04-29

I know this is a duplicate, but I cannot figure this out. I have a file structure like: enter image description here

How can I link factoid-page.js into factoid-page.html ?

I have tried: <script type="text/javascript" th:src="@{/factoid-page.js}"></script>

This does not work.

Please help, Thanks

CodePudding user response:

Accroading to this page: Add CSS and JS to Thymeleaf

For CSS and JavaScript files, the default directory is src/main/resources/static..

Please reorganize your static folder:

  1. put .js files into src/main/resources/static/js/
  2. put .css files into src/main/resources/static/css/

and try this

<script type="text/javascript" th:src="@{/js/factoid-page.js}"></script>
  • Related