The new CSS property content-visibility
property looks like a nice tool to increase page loading speed.
I want to add it to my page footer:
<footer style="content-visibility: auto;">
(...)
</footer>
As it can be painted later on the screen (it appears below the folder for all my site's pages).
However, my page's footer has many js libs that are loaded there via <script>
tags inside the footer tag.
Some scripts are eager loaded, some are deferred and other are loaded asynchronously. (yeah, many scripts, unfortunately).
So my question is:
Will the content-visibility
property interfere with script loading in any way?
or will the scripts load the same way regardless of the CSS property?
Asking here as it's new and looks kind of "magic" to me, and I didn't find much related documentation. Thanks in advance for any insight on this.
It would be <footer style="content-visibility:auto">
not <footer content-visibility="auto">
.
It's a CSS property, so it won't affect script loading, but because it has the potential to affect the layout, script execution could be affected if it, for example, relied on a particular layout based operation such as getting the bounding box of a rectangle.
As you consider Alohci's answer as incomplete, I'll add my 2 cents, but mostly I can only rephrase that what already been said.
I don't have Chrome 85, so I can't test it. But after reading the specs this and this I think that:
...but if It was a script that adds a handler to an element, it may be faulty, like
$(selector).click(...)
?
Just test it! Try clicking an element with content-visibility: auto
with JS code while it's still invisible due to being off-screen. I'm sure handler will work. There is nothing in the specs about such matters.
Will the
content-visibility
property interfere with script loading in any way?
No. There is not a word about resource loading in the specs. But again - test it! Look at the Network tab. Script's load sequence shouldn't change.
So, it won't affect scripts that are of general use, like bootstrap and such, but [what] if it was a script that...
...a script that...
content-visibility: auto
or it descendants (Alohci already pointed it out)innerText
content-visibility
's spec is actually a draft)Yes it can break
You can even imaging a script that reads css properties, finds content-visibility
and throws as it's unknown to it... or even throws just because it's author hates those who use content-visibility
:)
But I think that in your case the chances are infinitesimal, as I suppose that non of the scripts you're referring to are interested in your footer
.
Anyway, any change should be tested (ideally). But also you can never be sure that there are no bugs. So just just try it, if it's worth it, and see how it goes.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With