Using Html5boilerplate's code to load JQuery very slow when run locally

情到浓时终转凉″ 提交于 2019-12-04 05:07:26

I'm guessing that you're not serving the HTML through a web server.

The // prefix on the url indicates that it should use the same protocol as the current resource (usually either http or https)

Since you're not serving through http and instead through a file, it's trying to look for it on your local file system, eventually timing out.

The network tab on Chrome inspector shows it trying to load the following for me:

file://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js
file:///C:/Users/[My Username]/Documents/jquery-1.7.1.min.js

It'll try to load those times and the file system (or maybe the browser) will eventually timeout.

The proper way is to serve it through a web server, either IIS if you're on Windows or Apache if you're on Linux/Mac (Apache also works in Windows, but IIS has better UI tools)

This line:

<script src="//ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>

Attempts to find jQuery in your file system, which means it will take a while to fail. While looking at the Network tab of the developer panel in Google Chrome, it attempts to look for the file in file://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js.Then, once it has failed to find the file, it loads jQuery (and successfully finds the file) using the next line:

<script>window.jQuery || document.write('<script src="jquery-1.7.1.min.js"><\/script>');

To remedy the problem, add https: to the src of your script tag, like so:

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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!