skip to Main Content

Previously I was using managed hosting but have recently been testing a VPS server setup running CentOs with Virtualmin.

I have moved over a website which works absolutely fine on the managed hosting, but moving it to the VPS gives me multiple JS errors. For some reason, it doesn’t seem to be loading any of the JS scripts. When I replace the scripts with CDN links, it all works fine again.

I’ve checked the directory permissions and they’re set the same as the previous hosting, I can also access and read each file using website.com/js/bootstrap.min.js for example. The only difference is the JS directory itself is "Forbidden". I’m not sure if that makes a difference when I can read the actual files?

My question is, why could this be happening if JS runs similar to HTML and works fine when using the CDN scripts? Also, what is the meaning of the random IDs contained in the JS SRC scripts right before text/javascript shown below, could this be the cause?

    <script src="js/jquery-3.2.1.min.js" type="7fb652456240e11add396d8d-text/javascript"></script>
    <script src="js/bootstrap.min.js" type="7fb652456240e11add396d8d-text/javascript"></script>
    <script src="js/jquery.slicknav.min.js" type="7fb652456240e11add396d8d-text/javascript"></script>
    <script src="js/owl.carousel.min.js" type="7fb652456240e11add396d8d-text/javascript"></script>
    <script src="js/jquery.magnific-popup.min.js" type="7fb652456240e11add396d8d-text/javascript"></script>
    <script src="js/circle-progress.min.js" type="7fb652456240e11add396d8d-text/javascript"></script>
    <script src="js/mixitup.min.js" type="7fb652456240e11add396d8d-text/javascript"></script>
    <script src="js/instafeed.min.js" type="7fb652456240e11add396d8d-text/javascript"></script>
    <script src="js/masonry.pkgd.min.js" type="7fb652456240e11add396d8d-text/javascript"></script>
    <script src="js/main.js" type="7fb652456240e11add396d8d-text/javascript"></script>
<script src="js/rocket-loader.min.js" data-cf-settings="7fb652456240e11add396d8d-|49" defer></script></body>
    </html>

enter image description here

2

Answers


  1. It seems that you didn’t put JQuery back on your new hosting.
    There are a few clues:

    ‘unexpected token’: jquery uses $
    ‘jQuery is not defined’

    It could also be that you put jQuery in a different location than where it was on your managed hosting. It could also be that it’s still pointing to your old hosting.

    If that doesn’t work, try removing the text before text/javascript (although I doubt that’s the issue, considering it worked on your old hosting). Also, Javascript’s mime type is application/javascript.
    Try checking those. That should fix your problem.

    Login or Signup to reply.
  2. I can also access and read each file using
    website.com/js/bootstrap.min.js for example. The only difference is
    the JS directory itself is "Forbidden".

    This doesn’t make sense. Either the folder is forbidden or it is not.
    If you can access that folder through the browser url, then clearly it is not forbidden. If you get a ‘Forbidden’ message in your browser, then obviously the folder is forbidden and you found the problem.

    My question is, why could this be happening if JS runs similar to HTML
    and works fine when using the CDN scripts?

    Go to the network tab in your browser and check the http status that you receive in the browser for the resource that you request, i.e. jQuery in this case. The error that bootstrap throws is probably just a consequence of the fact that jQuery isn’t loaded. I guess there must be a dependency.
    If not, in the absolute worst case you can load the unminified version of the script that throws, and debug the problem based on the original source code.

    The reason why it works for a CDN is obviously because these domains allow you public access to the resource it hosts, if not you wouldn’t be able to get it, and it is sort of the point of using a CDN.
    Btw, you should use a CDN, there is no clear argument as for why you shouldn’t for these common libs.

    Also, what is the meaning of the random IDs contained in the JS SRC
    scripts right before text/javascript shown below, could this be the
    cause?

    I assume that you mean in the type, not in the src attribute of the html.
    This is your code:

     <script src="js/jquery-3.2.1.min.js" type="7fb652456240e11add396d8d-text/javascript"></script>
    

    This doesn’t make sense. If anything, they look like generated hashes which often happen when you load chunks of Javascript asynchronously.

    It must be framework related, although I have no idea what framework you’re currently using. I don’t know if you’re using SSR, CSR, templating library, bundling library etc.
    But it should be clear that something generates this string for you. You need to check your template, what generates your template, and either way, remove the type altogether if you can. It’s really useless in that spot.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search