W3C home > Mailing lists > Public > www-style@w3.org > August 2013

Re: [css-om] CSSStyleDeclaration.parentElement

From: Rik Cabanier <cabanier@gmail.com>
Date: Sat, 24 Aug 2013 13:33:09 -0700
Message-ID: <CAGN7qDCRit3_NfvCjutQBGMV=NRji8JRjCar+T_z2PXpnjcgGw@mail.gmail.com>
To: François REMY <francois.remy.dev@outlook.com>
Cc: Sylvain Galineau <galineau@adobe.com>, Simon Pieters <simonp@opera.com>, www-style list <www-style@w3.org>
Do you have examples where authors are doing this caching to work around
performance problems?

If so, it seems that this should be fixed in the browsers themselves (ie by
caching the last result of getComputedStyle). No need to invent a new API

On Sat, Aug 24, 2013 at 12:55 PM, Francois REMY <
francois.remy.dev@outlook.com> wrote:

> > Nonetheless, if this is really the best use
> > I can make of my time, I'll try to find other
> > use cases during the weekend, we'll see
> > what comes out of it.
> Saturday's morning idea:
> - since getComputedStyle return a new object every time, you do not want to
> call this function multiple times.
> - as a result, your code contains functions where you can give a reference
> to the computed style of an element in addition to the element itself (ie:
> cache parameters)
> - let's figure out that you made a mistake somewhere in your code and gave
> a
> reference to the wrong style object, how do you find this out?
> If you've parentElement you can do sanity checks at the beginning of your
> function:
>     if(elementStyle.parentElement != element) {
>         if("debug" in window) debugger;
>         elementStyle = getComputedStyle(element);
>     }
> The only option now would be to call getComputedStyle again and comparing
> all properties in the hope you find a difference. This is so slow you
> couldn't even keep that sanity check in production. Since you're calling
> getComputedStyle anyway, it cancels the effect of the cache.
Received on Saturday, 24 August 2013 20:33:35 UTC

This archive was generated by hypermail 2.4.0 : Friday, 25 March 2022 10:08:33 UTC