Search code examples
javascriptjettyfreemarkerspark-java

Include javascript file in freemarker template using spark


I've tried to include javascript file in ftl (Freemarker Template)

js script tag

but I keep getting this message

console error

I'm using Spark framework which has Jetty server. This happens every time I try to include any file, even just an image. With css I've used <#include "style.css"> but it's workaround.

Is there any way to include scripts?


Solution

  • You must use staticFileLocation to tell where static files like *.js and *.css are placed, so spark will serve them directly.

    Secondly, don't include css like that:

    <#include "css/style.css">
    

    because it will end up with css rules inside <head> tag, which will not work.