• I want to reduce loading from external sites. Currently I do this <head> load:

    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>

    I like to change that to:

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

    But I am not sure where to put it on the server, and how to write the path.

    Wordpress is in /httpdocs/ however my files are usually in /files/ which is outside /httpdocs/ (or parallel).

    How can I write the path?

Viewing 4 replies - 1 through 4 (of 4 total)
  • It’s normally recommended to always use a full URL, not a partial location like above. it just takes the possible guess work out of file locations, both for browsers nd us developers that have to come and look at it later on. 🙂

    As for the path, it doesn’t matter where you put it as long as you can access it. If it was me, I’d have a folder on the main root of the site and sit it in there.

    /root/
      /javascript/
        /jquery.js
    /wp-content/
    index.php

    Then have the script location set like this:

    $location = home_url( '/javascript/jquery.js' );

    Shariq Khan

    (@shariqkhan2012)

    Doesn’t WordPress load jQuery by default?
    I don’t think you need to load it again from some other source because WP already bundles that in.

    Thread Starter yellofish

    (@yellofish)

    @shariqkhan2012
    Doh! You are right. I tried the page with the removed link and it worked fine.

    But I have another one that like to store locally:

    <script src="https://cdn.datatables.net/1.10.21/js/jquery.dataTables.min.js"></script>

    what’s the best place to put it, and how can I link it? I am not sure what the root is.

    Shariq Khan

    (@shariqkhan2012)

    what’s the best place to put it

    It depends on whether the script in question is a part of a plugin or a theme.
    If you need the script for a plugin that you are writing, then store them inside a sub-directory within your plugin (or theme)

    However, if the script in question has no link to your plugin (or theme), then you shouldn’t bother with it.

    May I ask whats your use case?

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘What is the path for jquery.min.js ?’ is closed to new replies.