jeudi 27 octobre 2016

Import JS and CSS in htmls

I'm new to web development and can't seem to understand this. My Node.js project has the following structure -

public - 
       |-js-
           |-a.js

       |-css-
            |-a.css

       |-htmls-
            |-a.html

I have set up the static middleware to the public folder.

webServer.use(express.static('public'))

Why do I have to do something like this to include a.js in a.html

<script src="../js/a.js"></script>

instead of

<script src="js/a.js"></script> ?

since I have set up routes that the static content be served from the public folder? How does the request for a.js goes to my server?

If I do something like this -

public - 
       |-js-
           |-a.js

       |-css-
            |-a.css

       |-htmls-
            |-a.html
src - 
    |-views-
           |-b.html

In my b.html i am able to use the a.js by just using

<script src="js/todo.js"></script>   

Why is this?




Aucun commentaire:

Enregistrer un commentaire