CSS monkeyage

Posted by Simes at 1:41 pm
Jun 182005

Our app has kind of a portal-y front-end on it, which means we have a frame set with between two and four frames, all of which use basically the same CSS. The CSS is not cacheable because we’re running over https, so it adds a substantial amount to the payload for any given portal page.

The solution? Load the CSS into the frameset, and use this bit of code right here in the onLoad() of each of the in-frame documents:

function loadStylesFromRootWindow()
{
    var sheets = window.top.document.styleSheets;
    for (var i = 0; i < sheets.length; i ++)
    {
        var sheet = document.createStyleSheet();
        sheet.cssText = sheets[i].cssText;
    }

}

I should probably mention that there's almost certainly no chance of this working with anything other than IE, but in a closed environment such as this I don't care. :)

© 2011 simes dot org Suffusion theme by Sayontan Sinha