简体   繁体   中英

How to include a .js file into an html file that is served by a compojure server?

One of my html file needs to include a script file, as it often happens, and no matter what I do, the browser doesn't seem to get it.

following this answer: How to include css files into compojure project?

I created a public folder in my resource folder. The structure looks like this:

resources
|-public
  |-views
  |   |-myview.html
  |-scripts
     |-my.script.js

Inclusion of the file in myview.html looks like this:

<head>
    <script src="/scripts/my.script.js"></script>
</head>    

When I request myview.html from the server I get it, but all of the types in my.script.js are unknown. The html works as expected when I just load it in the browser (I have to adjust the path to the script file to be relative, of course, and no, that doesn't work either when I request it from my server).

So how do I get my script files (and later css files) to be found by the html in a typical compojure setup?

Turns out I was just missing

(route/resources "/")

in my routing. As that wasn't the problem with the topic I looked at, I didn't figure it out for a while. Turns out sometimes you should read the code in the question just as carefully as the answer...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM