网站在 iPad/iPhone 上在 3G 下显示 JavaScript 错误,但在 WiFi 下没有 [英] Web site exhibits JavaScript error on iPad / iPhone under 3G but not under WiFi

查看:21
本文介绍了网站在 iPad/iPhone 上在 3G 下显示 JavaScript 错误,但在 WiFi 下没有的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 3G 下的 iPad 上连接到 http://www.manage-us.com [使用to] 导致 JavaScript 错误,如果已启用开发者控制台,则可以看到该错误.如果在 WiFi 连接下使用同一 iPad 访问同一页面,则不会显示错误.[错误现已消失,因为我应用了下面的修复程序!].

Connecting to http://www.manage-us.com on an iPad under 3G [used to] result in a JavaScript error which can be seen if the developer console has been enabled. If the same page is accessed using the same iPad under a WiFi connection no error is displayed. [The error has now gone because I applied the fix below!].

这是为什么?

我尝试在 Mac 上的 Safari 和 Mac 上的 iPad 模拟器上模拟低带宽(使用 dummynet).这不会重现该问题.

I've tried simulating low bandwidth (using dummynet) on Safari on Mac and on the iPad simulator on Mac. This does not reproduce the problem.

我目前怀疑这是我在英国 (O2) 的移动运营商引入的问题,该运营商已知通过代理缓存修改某些内容,例如降级图像文件.如果您可以通过其他移动运营商确认在 iPad 或 iPhone 上通过 3G 连接时没有遇到此问题,那将会很有帮助.

I am currently suspecting this is a problem being introduced by my mobile operator in the UK (O2) which is known to modify some content through a proxy cache such as downgrading image files. If you can confirm that you don't experience this problem when connecting by 3G on iPad or iPhone through another mobile operator that would be helpful.

推荐答案

我对此进行了进一步调查,发现问题在于英国移动运营商 O2(Apple 最初的独家 iPhone 运营商)在发送之前修改了网页内容它适用于 iPhone 和 iPad.可能在将其发送到任何运行移动浏览器的设备之前.

I've investigated this further and discovered that the problem is that the UK mobile operator O2 (the original exclusive iPhone operator for Apple), modifies web content before sending it to iPhones and iPads. Probably before sending it to any device running a mobile browser.

它们不确定地将一些 CSS 和 JavaScript 内联到网页的主要源文件中.这可能会产生错误,原因可能是他们的算法错误,或者是由于源文件中的语法错误而从源文件中剥离空格的结果,否则这些错误是良性的.

They non-deterministically inline some of the CSS and JavaScript into the main source files of the web pages. This can create errors either because of mistakes in their algorithm or the consequence of stripping white space from source files with syntactic mistakes in the source files which were otherwise benign.

这些修改还从受版权保护的 javascript 库和 css 库中剥离了版权信息,并对交付优化造成了严重破坏.

These modifications also strip copyright messages from copyrighted javascript libraries and css libraries and play havoc with delivery optimisations.

例如,假设用户正在访问您网站上的一系列页面,这些页面都链接到 jQuery 库.O2 不是让您的移动浏览器在本地缓存库,而是在每个页面上内联库,迫使您的手机为每个页面一遍又一遍地加载整个库.

For example, imagine if a user is visiting a sequence of pages on your site which all link to jQuery libraries. Instead of letting your mobile browser locally cache the library, O2 inline the library on every page, forcing your phone to load the entire library over and over again for every page.

我在这里写了一篇关于这个问题的博客,希望能引起更多关注:http://stuartroebuck.blogspot.com/2010/07/mobile-proxy-cache-content-modification.html

I've written a blog about the issue here in the hope if drawing a bit more attention to this: http://stuartroebuck.blogspot.com/2010/07/mobile-proxy-cache-content-modification.html

我的解决方法是使用 document.write() 在加载时插入 JavaScript 库依赖项并防止 O2 内联它们.这似乎工作得很好.例如:

My workaround is to use document.write() to insert the JavaScript library dependencies at load time and prevent O2 from inlining them. This seems to work quite well. e.g.:

<script type="text/javascript">
// <![CDATA[
// Using document.write to load JavaScript dependencies to bypass O2 network inlining of JavaScript.
function loadJS(file){document.write("<" + "script type='text/javascript' src='" + file + "'></" + "script>")}
loadJS("/js/jquery-1.4.2.min.js");
loadJS("/js/myJSLibrary.js");
// ]]>
</script>

请注意,与以往一样,如果页面以 XHTML 形式提供,document.write 将不起作用.

Note that, as ever, document.write will not work if the page is served as XHTML.

这篇关于网站在 iPad/iPhone 上在 3G 下显示 JavaScript 错误,但在 WiFi 下没有的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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