Fancybox causing slow load times in IE?

2020-03-05 06:54发布

问题:

I'm using Fancybox v.1.3.4 to display videos in an iframe on this page. The Fancybox and the videos display fine, but the problem is that, since adding the code, I'm getting a huge pause when loading up the site in IE7/8, similar to this issue—the page loads, and then the UI freezes for a good 4-5 seconds, preventing me from clicking on links, scrolling, or anything else. Here's what I have linked at the top of the page, in the <head>. The jQuery UI pack (incl. UI 1.8.11, UI Widget, UI Mouse, UI Position, and UI Effects w/ Scale) is included mainly to enable other effects that aren't yet loaded on the site, but will be.

<script type="text/javascript" src="/lib/jquery/jquery-latest.min.js"></script>
<script type="text/javascript" src="/lib/jquery/jquery-ui.custom.min.js"></script>
<script type="text/javascript" src="/lib/fancybox/jquery.fancybox-1.3.4.pack.js"></script>
<link rel="stylesheet" href="/lib/fancybox/jquery.fancybox-1.3.4.css" />

I used YSlow on the page, which suggested moving the script calls to the bottom, but that didn't fix the pause in IE. I then took a look at the HTML DOM during load using IE8's Developer Tools, and the pause seems to occur as the code for the Fancybox is loading; immediately after the pause, the following divs appear at the bottom of the tree:

<div id="fancybox-tmp"/>
<div id="fancybox-loading" (jQuery attribute here)>
...
</div>
<div id="fancybox-overlay"/>
<div class="fancybox-ie" id="fancybox-wrap">
...
</div>

That, along with the fact that the problem appeared after I added the fancybox to the page, is why I figured it's a performance problem with Fancybox, but nothing I've tried so far (short of taking the fancybox code off) seems to have had an impact. The latest thing I've tried is removing references to jQuery.ready(), in case that might have helped it to load the fancybox code earlier and thus change the timing of the pause, but it didn't do much good. Not that I really expected it to, but I'm a bit new to jQuery and Fancybox and at this point I'm grasping at straws.

What I'm thinking now is that it might be a conflict between Fancybox and one of the other scripts on the page, such as Google Analytics, but I'm not exactly sure how to tell if that's the case, or what to do if that ends up being it. Any ideas from people who know their way around these scripts? Thanks in advance.

回答1:

I've experienced a similiar problem with fancybox and IE before. If you look in the CSS file, there are a tonne of IE specific filters:

/* IE6 */

.fancybox-ie6 #fancybox-close { background: transparent; filter: 
progid:DXImageTransform.Microsoft.AlphaImageLoader
(src='fancybox/fancy_close.png', sizingMethod='scale'); }

/* and so on */

In my project, I removed all of these IE specific rules and the freezing problem goes away. See if that resolves it; else the problem may be somewhere else.



回答2:

you could use firebug to profile your code



回答3:

I also had this problem with Fancybox in IE. For me it was a bug in jQuery introduced in v1.6.0. Upgrading to the latest jQuery version (1.6.4) fixed the issue.

More details at the Fancybox google group