[ 7 posts ]

Corey T.

  • Username: onpubcom
  • Joined: Fri Sep 10, 2010 2:25 pm
  • Posts: 6
  • Twitter: onpubcom
  • Offline
  • Profile

MenuNav Node plugin slow to render.. Why?

Post Posted: Thu Apr 21, 2011 2:57 pm
+0-
Hi all, I notice that on my site and also in the YUI doc examples, the MenuNav plugin (http://developer.yahoo.com/yui/3/node-menunav/) renders fairly slow.. There's a very noticeable lag between the time the page renders and the time the menu is actually displayed.

Here's a link to the JS I'm using to load the plugin: http://onpub.com/onpub/frontend/js/site.js

I am loading some custom CSS to override the default menu style, but even without that, the rendering of the menu is still rather slow.

Does anyone have any tricks to speed this up? For example, if I load the YUI JavaScript includes earlier in my code, will the menu render faster?.. I've tried various tweaks like this but have yet to get great performance out of this plugin..

Are they any plans to improve the performance of this widget?

Thanks in advance for any advice.

CT
http://onpub.com/

Ryan Grove

YUI Developer

  • Username: rgrove
  • Joined: Tue Dec 09, 2008 9:55 pm
  • Posts: 275
  • Location: Portland, OR
  • Twitter: yaypie
  • GitHub: rgrove
  • Gists: rgrove
  • IRC: rgrove
  • YUI Developer
  • Offline
  • Profile

Re: MenuNav Node plugin slow to render.. Why?

Post Posted: Thu Apr 21, 2011 3:45 pm
+0-
After taking a look at onpub.com, it looks like there are several problems contributing to the amount of time it takes to render a menu (most of them are not related to node-menunav itself):

First, YUI's JS and CSS modules are being loaded individually from your server, not via a combo handler or CDN. The results in a huge number of HTTP requests in order to pull in node-menunav and all its dependencies, which significantly increases the delay before the menu JS can actually start executing. To fix this, I'd recommend either loading YUI from the Yahoo! CDN (which will use combo-handled requests to improve performance) or combine your self-hosted modules into a single JS and a single CSS file.

Once the number of HTTP requests has been cut down, the next thing you can do is add some custom CSS to the page to prevent the menubar pop-in effect. YUI adds a .yui3-loading class to the <html> tag while it's loading, so you can use this to add some CSS that creates a placeholder area on the page with the same dimensions that the rendered menu will occupy. This way once the menu is actually rendered, it will simply appear in place rather than having a jarring pop-in effect that pushes the rest of the page down.

YSlow can give you more performance advice along these lines: http://developer.yahoo.com/yslow/

In any case, most of the performance cost here is in what's happening before the menu JS even starts running, so once you decrease the load time and number of HTTP requests, you should see that the actual render time for the menu itself is minimal.

Corey T.

  • Username: onpubcom
  • Joined: Fri Sep 10, 2010 2:25 pm
  • Posts: 6
  • Twitter: onpubcom
  • Offline
  • Profile

Re: MenuNav Node plugin slow to render.. Why?

Post Posted: Fri Apr 22, 2011 11:51 am
+0-
Hi Ryan, thanks for your suggestions. I made my code use the CDN and now things seem a little snappier.. Also, I am already using the "yui3-loading" CSS class to hide the menu div until it's rendered.

There is still that jarring effect between the time the page renders and between the time the menu renders in the space it belongs, as you pointed out..

Do you have a technique for filling the space before hand so that the menu just appears instead of popping in to place?

I think I've tried something along those lines before but was unsuccessful.. I believe my difficulty was choosing an object to put there with the exact dimensions of the menu before the menu is actually displayed..

How would I go about calculating the size of the menu before it actually renders? Not sure there is a foolproof way to do this since the size of the menu could be different dependent on various client factors such as font size, font family, style customizations etc.. Is there some magic formula I could use to calculate the size of the menu before hand and fill the space with an empty <div> or something like that before the menu is ready to be displayed?

Thanks,

Corey

Ryan Grove

YUI Developer

  • Username: rgrove
  • Joined: Tue Dec 09, 2008 9:55 pm
  • Posts: 275
  • Location: Portland, OR
  • Twitter: yaypie
  • GitHub: rgrove
  • Gists: rgrove
  • IRC: rgrove
  • YUI Developer
  • Offline
  • Profile

Re: MenuNav Node plugin slow to render.. Why?

Post Posted: Fri Apr 22, 2011 2:05 pm
+0-
Definitely feels much snappier now that you're using the CDN!

One thing you can do to fill the menubar space accurately is manually include the MenuNav CSS on the page by adding this to the <head>:

Code:
<link rel="stylesheet" href="http://yui.yahooapis.com/combo?3.3.0/build/node-menunav/assets/skins/sam/node-menunav.css">

<style>
/* Hide menus while the JS is still loading, but keep the menubar visible. */
.yui3-loading .yui3-menu { visibility: none; }
</style>

I haven't tested this, but I think it should work.

Corey T.

  • Username: onpubcom
  • Joined: Fri Sep 10, 2010 2:25 pm
  • Posts: 6
  • Twitter: onpubcom
  • Offline
  • Profile

Re: MenuNav Node plugin slow to render.. Why?

Post Posted: Sat Apr 23, 2011 8:01 am
+0-
Your post gave me the idea to modify my CSS as follows:

Code:
.yui3-loading #onpub-menubar {
/* the old way: display: none; */
/* the new way: */
visibility: hidden;
}

Basically this makes the menu now "appear" in place instead of "popping" vertically in to empty space.

If you look at my site again you'll notice this, but there is still a noticeable lag between the time the menu appears and the time my custom CSS is applied. You'll notice the stock dark menu border changes to the lighter color defined by my custom CSS. Just gotta figure out now how to make that transition a little smoother.

May I suggest that the YUI docs team add some type of notes about these loading/rendering issues to the menunav plugin docs/examples.

Also, one idea I had to enhance this plugin would be to give the option to define a CSS file as a custom config attribute, for example:

Code:
this.plug(Y.Plugin.NodeMenuNav, { customCSS: 'path/to/custom-menu-skin.css' });

Ideally this new option would cause the plugin to load the custom CSS file and then apply any CSS class modifications before the menu is even displayed. This might enable a smoother rendering of the menu than what I'm getting currently by applying my custom style after the the plug method is called.

Would be nice to be able to load the custom style before the menu rendering process is complete.

Thanks for all your help in figuring this out.

Corey

Ryan Grove

YUI Developer

  • Username: rgrove
  • Joined: Tue Dec 09, 2008 9:55 pm
  • Posts: 275
  • Location: Portland, OR
  • Twitter: yaypie
  • GitHub: rgrove
  • Gists: rgrove
  • IRC: rgrove
  • YUI Developer
  • Offline
  • Profile

Re: MenuNav Node plugin slow to render.. Why?

Post Posted: Mon Apr 25, 2011 9:10 am
+0-
Feels much faster now. I agree we should add a section to the MenuNav docs explaining how to minimize the pop-in effect. Thanks for the suggestion!

I'm less convinced that we need to add a config attribute to MenuNav that loads custom CSS; in fact, this wouldn't solve the problem at hand, since MenuNav's CSS is loaded by the Loader at the same time as the JS. The easiest way to work around this would be to load your custom CSS manually before even calling YUI().use('node-menunav', ...).

Alternatively, you could set YUI's fetchCSS config value to false (e.g. YUI({fetchCSS: false}).use( ... )) to prevent the Loader from loading any CSS at all. You could then load both your CSS and MenuNav's CSS whenever you want, so you'll have full control over the timing.

Corey T.

  • Username: onpubcom
  • Joined: Fri Sep 10, 2010 2:25 pm
  • Posts: 6
  • Twitter: onpubcom
  • Offline
  • Profile

Re: MenuNav Node plugin slow to render.. Why?

Post Posted: Mon May 02, 2011 4:41 pm
+0-
Thanks again. The fetchCSS config property gives me the control I need to load the menu CSS along with my customizations long before the menunav plugin is loaded. This actually makes the menu render much faster as well. Now there's no lag between the time the menu displays and the time my style customizations are applied. This is the only way I'm able to get my customizations to apply smoothly. The menu now renders as I intend it to, as soon as its displayed.

I actually tried the first suggestion of manually loading my CSS before calling YUI().use. This didn't work since when the loader downloads the menunav CSS it clobbers my customizations. That why I was using YUI.get.css to load my CSS after calling plug on the menu node.

If I can humbly suggest adding these two things to the docs in addition to what I previously suggested:

1. Document fetchCSS at: http://developer.yahoo.com/yui/3/yui/#loader. Currently the page says "The valid configuration options for Loader are as follows." This led me to believe that the list of config properties listed on the page was a complete list, yet there's no mention of fetchCSS. It's only after you mentioned it that I thought to look at the API docs and found more info: http://developer.yahoo.com/yui/3/api/config.html#property_fetchCSS. Maybe just link to the full API doc if you all don't want to list every property on the main doc page.

2. On the http://developer.yahoo.com/yui/3/yui/ page maybe add some some description of the order things are loaded in. It was not obvious to me that the menunav CSS would be loaded by the loader. I assumed that the CSS was being dynamically loaded once the plug method was called. Once you said how it works I used Firebug to confirm and I saw what you described. A blurb about this might save others some time. Sorry if there's already something there about this and I just didn't see.

I should also note that front-loading all the CSS before </head> is actually faster since it seems the browser is better able to cache the files. Not sure there's any browser caching going on when the CSS is loaded dynamically either via the YUI loader or via YUI.get.css. I'd have to look in to this a little further though to see if this is actually true.

Why did the YUI team decide to load CSS along with JavaScript when calling YUI().use? For the menunav plugin, on the surface it would make sense to delay the loading of the CSS until plug is called. Then it would make sense to have a menunav config attribute to supply a custom CSS file that selectively overrides the default SAM skin classes. I would guess this way of customizing the menu CSS is more common then actually re-defining all the SAM skin classes from scratch. There's so many, so I chose to pick and choose the classes to tweak. I placed my customizations in a separate file, making it necessary to load this file after the stock skin is loaded. It's just easier to maintain this way.

In the meantime, using fetchCSS: false is more than workable for my needs.
  [ 7 posts ]
Display posts from previous:  Sort by  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum