The Blog

End of the road?

My long-time readers may remember that, back in the early days, ADxMenu had two versions. One that used .htc file and only one set of styles and the other that used only javascript but two sets of styles. The reason was that .htc version at that time used original Peter Nederlof’s csshover.htc which went through entire document looking for elements to apply :hover trickery and thus had far from good performance on very long pages.
Things changed when I recoded it to work only with menu elements and ADxMenu 3 utilized it to its fullest potential.

However, performance issues are not defeated yet. In the last project I’m working on, I have three menus on one page and two of them are very large. The page itself also features a great deal of various positioning, using both floats and pos/abs position. Accompanied with these three menus, this brings IE to its knees — it takes him 4-5s on P4-2.8GHz with half-gig of RAM to render that page and execute the .htc. 90% of that freeze time goes on .htc processing.
But not only that. Since my css applies position:relative on li:hover and thus does the actual positioning in that moment, re-rendering of the page takes some time and going from one menu option to another has a very noticeable lag. Last time I have seen such behavior was with Netscape Navigator 4. Sigh…

I created test page with completely stripped-down page leaving just menus where you can still notice the lag, both on page load and when traversing the left-hand menus — for a fraction of second you can see the busy cursor popping up. The numeric value in the middle is how long it takes IE to complete the .htc processing. And than imagine how this looks like when Sports menu has 3x more items (as is the case on production environment).

I spent entire afternoon, measuring where is all this time spent. It appears that each currentStyle.addRule call takes about 50-60ms, and some 1s is lost on function calls overhead. I don’t see a solution with .htc anymore as it seems that IE’s Trident engine has its limits. Pages that use heavy positioning are simply not what IE can handle well. I could be wrong, but the more positioning I add, the less responsive it becomes.

It is time for different IE strategy. I could easily end up dumping .htc all together and go back to Javascript and delayed initialization. This could prove to be a good thing after all.

For those interested, I resolved the perfomance problem by completly removing .htc, rewriting the design rules so that none of them used li:hover and execute this script on window.onload:

JavaScript:
  1. xGetElementsByClassName("adxm", document, "ul", function(oUL) {
  2. xGetElementsByClassName("submenu", oUL, "li", function(oLI) {
  3.  
  4. oLI.onmouseover = function() {
  5. if (!this.UL)
  6. this.UL = oLI.getElementsByTagName("ul")[0];
  7. this.UL.style.visibility = "visible";
  8. }
  9.  
  10. oLI.onmouseout = function() {
  11. this.UL.style.visibility = "hidden";
  12. }
  13.  
  14. } );
  15. } );

And this works near instant.

Banca

Banca

Beautiful and functional currency converter, supports just about any currency in the world.

Go Couch to 5k

Go Couch to 5k

The most popular starter running program in beautiful feature-rich app (GPS tracking, charts, detailed history etc)

Quickie to do

Quickie to do

The fastest short-term task-list / check-list app on the App Store. Really.

Guerrilla Cardio

Guerrilla Cardio

The most challenging high-impulse interval training in the world.

Run Mate

Run Mate

A versatile running coach app, with unlimited number of running programs. Perfect for casual runners.

5 Comments

Feel free to chime in, looking forward to it. Leave a Comment

  1. Neil says:

    I’m curious if you have any examples on integrating this great menu system into WordPress. I’m hoping to create a theme for a custom site that relys heavily on WordPress pages, which I’d like to have appear as a horizontal menubar with drop-downs.

    However, a quick read-through of your instructions seems to indicate that the class and id markups in the HTML required to support your CSS and scripts are likely incompatible with WordPress out-of-the-box (i.e. the “submenu” indications, etc.). Is there anywhere you can point me to learn how to integrate your excellent work into a WordPress theme correctly?

    Much appreciated–and I love the look and feel of your site!

    Neil

  2. Bertrand says:

    Hi,

    I have the performance problem as well, but I don’t get the solution you’ve just posted. Could you post some packaged example ?

    Thanks for this great work anyway,

    Bertrand

  3. Aleksandar says:

    Neil, you can see the integration right at this site, in the menu at the top. It required a change of category output functions, something I plan to remedy in next update, so I can freely take on future updates on WP.

    Bertrand, I don’t have time to prepare an example at the moment. The one I gave is there because I needed a test-case to resolve the problem at work.

    The logic behind the JS code is:
    1. find all UL elements with adxm class
    2. find all LI elements that are childs of UL found in the first step and has submenu class
    3. for each such LI, attach event handlers that show/hide submenu on mouse actions

    For this, I have used xGetElementsByClassName functions from Mike Foster’s fantastic X library.

    The final version that will be used on the web site in question is more complicated, as I had to cater for different things in that specific layout. I’m building on the experience gathered during that development and will (when time allow) create ADxMenu 4.
    I’m still weighing pro and cons for some decisions regarding ver.4 so it will have to wait a bit more…

  4. btfans says:

    waiting for your great work on v.4

  5. Johan B says:

    Nice work!

    I will try your menu out next time I need a dropdown.

    I have been working with a complex menu for a client (cannot show this yet) and have stumbled into many of the problems you have found. I am currently using xCollapsible (and have tried xMenu) from the X library. Have you checked this out yet?

    My version is rewritten to handle a lot of extra layout and closes all open submenues in a way that works the the layout. It also has a little opening for a function that can hide select boxes when some submenu is open.
    I am also using csshover.htc, and don’t have time to rewrite the menu without this, but the speed problems aren’t that horrible. It takes more time to handle mouseover in long submenus, but the menus open and closes very quickly.

    I currently have problem with Safari, which don’t open submenus at all… Do you know any more of the specific problems Safari has with your menus? Or if there is a good way to send some css only to Safari (like a IE5 filter but for Safari)?

Comments are now closed for this article.