加载javascript文件,但取消的话它的时间太长? [英] Load a Javascript file, but cancel if it takes too long?

查看:126
本文介绍了加载javascript文件,但取消的话它的时间太长?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

任何人有加载JS文件,但取消载入它的好方法,如果时间过长?

Anyone have a good way to load a JS file but cancel loading it if it takes too long?

我想是这样的,假设:

<script type="text/javascript" cancel_after="2000" src="myfile.js"></script>

脚本为code,它需要在头得到加载,因为它取代页面上的元素,所以浏览器需要加载它阻止。但在情况下,服务器时间过长回应,我希望能够让浏览器进行,不会加载脚本。

The script is code that needs to get loaded in the head, because it replaces elements on the page, and so the browser needs to block while loading it. But in case the server takes too long to respond, I'd like to be able to have the browser proceed without loading the script.

推荐答案

使用一个preloader。我个人preFER yepnope ,在这里你可以轻松地设置使用超时 yepnope.errorTimeout = 2000

Use a preloader. I personally prefer yepnope, where you can easily set a timeout using yepnope.errorTimeout = 2000

检查链接的页面yepnope一个相当完整的文档。

Check the linked page for a rather complete documentation of yepnope.

这篇关于加载javascript文件,但取消的话它的时间太长?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆