-
Notifications
You must be signed in to change notification settings - Fork 8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: improve cumulative layout shift #305
Conversation
Thanks for the context @andybroomfield those two issues are interesting, in #125 if we go serverside for display handling and read the cookie there and hide before it gets to the client side we can then remove a lot of the cookie checking handling from the JS side and will no longer need to look at switching to localstorage. With #125 and how it is currently handled you still get a flash of banners due to it being hidden on the backend for all banners and then showing them all briefly before the frontend cookie checks kicks in. I'll do some further investigation on shifting the rendering to serverside and see where I get and update on #125. |
@andybroomfield I'll roll a separate PR for discussion on the backend handling, I've got it working locally so will push it up this evening once I've replaced the jQuery dependencies with pure javascript. We can then discuss cases I might have missed when implementing backend handling around caches. |
A couple of tests with this branch, first as logged in user (so non anon cache) Alert.banner.show.by.deafault.mp4And then logged out, with the internal page cache. Alert.banner.show.by.default.anon.mp4Seems to work ok on page refresh too. I notice we're just changing which way round we decide to show / hide the banner (show by deafult). This means that.
|
Thanks @andybroomfield those tests were helpful could you do the same test for this WIP PR which uses the backend on checks #306 you'll likely have to add the It's very work-in-progress that PR, but so far I've;
|
Correct there are likely to be more anonymous users that visit a website whether they are real users or bots such as Google via search console and PageSpeed, so improving CLS will help with search ranking scores and other similar metrics around performance and page rendering, especially on the likes of homepages. So these are the cases;
|
I'm discussing this with our digital content team internally to check what would work for them. |
I know at Greenwich we definitely don't want a flash on page load. @ekes is suggesting can we use bigpipe , and what about https://www.drupal.org/project/big_pipe_sessionless ? Would this help? |
Without basically repeating things others are saying, I don’t have much to add here. I guess it gets down to:
I guess then we have to ask ourselves what's more important, a small accessibility improvement or a small CLS improvement? |
From Brigthon Digital Content team: We would prefer to not have the flash on the banner after it is closed. They also mentioned that this could be an accessbility issue for triggering a flash on each page load. So it looks like we should keep the current method for now, unless we can make this an option. We could also look at Big Pipe mentioned above or trying to work out a way of caching by cookie for the page cache to get #306 working. |
Thanks @andybroomfield let's close this PR, I may work on some PageSpeed best practice documentation around CLS and add a note that the more alerts shown on a page the greater the CLS impact is |
I've been investigating a CLS (Cumulative Layout Shift) in PageSpeed and ways to improve it; after some debugging I found it is coming from the alert banner module.
My understanding of how it renders from looking at the code is as follows;
hidden
class is added inlocalgov_alert_banner.module
herehidden
class, and then if it's in the user's cookie hide the alert here.Due to this, the use of
hidden
in step 1 and removing the class in step 2 is redundant and instead causes a large CLS chained onto the elements below it where we are hiding by default and then unhiding all the alert banners and then hiding again, this PR resolves this and doesn't hide the alerts unless they are in the user's cookie.I've attached the before and after below;
Before
After
cc: @markconroy to confirm my findings on this.