Include jQuery outside the root directory

0

I have the following directories:

  • Dev
    • libs
      • jquery.js
    • Projects (Root)
      • index.html

In my index.html, I'm trying to use jquery as follows:

<script src="../libs/jquery.js"></script>

However, it does not work. It's as if the '../' was ignored. How can I include jquery as it is outside the root directory? I want to use a single centralized jquery in one place.

    
asked by anonymous 04.07.2018 / 23:39

1 answer

0

If the root of your application is at the Projetos level, you can not return a directory above it.

Option 1:

You simply copy your lib folder folder into projects

<script src="/libs/jquery.js"></script>

Option 2:

You would need to change the mapping to Dev but your address would be localhost/projetos/index.html .

Option 3:

You configure another site to serve your static files and load them as if it were an external CDN

<script src="//localhost:8080/libs/jquery.js"></script>

Option 4:

Use some tool to manage your dependencies and generate distribution packages for them in a dist directory within the level of your root, in the Projetos case. This would even allow you to compress and or minify these static files. However you will need to study and choose the one that suits you best, I recommend: Yarn , or Gulp or Webpack or Grunt

    
05.07.2018 / 18:28