- This topic has 11 replies, 4 voices, and was last updated 4 years, 8 months ago by
David.
-
AuthorPosts
-
July 15, 2021 at 1:39 pm #1857336
Rostyslav
Hello,
I want to reduce the LPC of my pages. I perfectly know what really makes that LPC high is the background image. What is the best choice to avoid that?
1) Preloading that image?
2) Lazy loading that image?If so, how can I achieve that manually?
July 15, 2021 at 2:16 pm #1857356Leo
StaffCustomer SupportHi there,
Does this thread help?
https://generatepress.com/forums/topic/preload-background-image/July 15, 2021 at 5:25 pm #1857431Rostyslav
So, which is the best choice to avoid that?
1) Preloading that image?
or
2) Lazy loading that image?
I use a container with a background image at the beginning of all my pages.
July 15, 2021 at 11:16 pm #1857584Elvin
StaffCustomer SupportHi there,
Preloading is generally the way to go.
Consider reducing the size of the container as well if possible.
July 16, 2021 at 2:21 am #1857717Rostyslav
Okay,
I have a different background image on all my pages. How can I preload them? What code and where should I write it?
Thanks!!!
July 16, 2021 at 5:09 am #1857825David
StaffCustomer SupportHi there,
how are you adding the image ? Is it within the post editor to the container block background ?
July 16, 2021 at 7:05 am #1857933Rostyslav
I added a container with generablocks and then background > URL image.
July 16, 2021 at 8:31 am #1858175David
StaffCustomer SupportUnfortunately there isn’t much that can be done about that – there a static image so theres no way i can dynamically request that image to be preloaded.
July 16, 2021 at 8:34 am #1858181Rostyslav
How can I do it manually?
July 16, 2021 at 9:29 am #1858248David
StaffCustomer SupportNot sure about this – but one option you can try is:
1. Set the Featured Image on the post, using the same image as the container background.
2. Then Disable it so it won’t display:https://docs.generatepress.com/article/disable-elements-overview/
3. Add this PHP Snippet to the site
add_action( 'wp_head', function() { if( is_singular() ) { $featured_img_url_full = get_the_post_thumbnail_url(get_the_ID(),'full'); echo '<link rel="preload" as="image" href="'.$featured_img_url_full.'"/>'; } },1000);July 16, 2021 at 9:35 am #1858253Rostyslav
Is a good idea instead using a plugin? So I can manually select which image to preload.
July 16, 2021 at 10:05 am #1858294David
StaffCustomer SupportIf there is a plugin that does that and it makes the process easier then for sure 🙂
-
AuthorPosts
- You must be logged in to reply to this topic.