Include jQuery outside the Root directory

Asked

Viewed 42 times

0

I have the following directories:

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

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

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

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

  • 1

    Are you putting ".. /libs/jquery.js" ? Have you noticed that all the path letters are in the high/low box as in the Folder names

  • Have you checked the Chrome Devtools Network tab for any errors? Or is there an error?

  • No console: GET http://localhost/libs/jquery/3.3.1/jquery-3.3.1.js 404 (Not Found)

1 answer

0


If your application root is at the level of Projetos, you can’t go back a directory above it.

Option 1:

You simply copy your lib 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 set up another site to serve your static files and upload 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 directory dist within your root level, in case Projetos. This would even allow you to compress and minify these static files. However you will need to study and choose the one you think best for you, recommend: Yarn, or Gulp or Webpack or Grunt

Browser other questions tagged

You are not signed in. Login or sign up in order to post.