CSS Preload images?

For support and discussion related to templates and themes in phpBB 3.3.
User avatar
Stoker 4.0
Registered User
Posts: 1660
Joined: Sun Feb 13, 2011 1:33 pm
Location: Funen, Denmark
Name: Ulrik Christensen

CSS Preload images?

Post by Stoker 4.0 »

Found this article: https://www.dhiwise.com/post/preload-im ... experience
Just wondering if its something we can use?

Code: Select all

/* Preloading CSS Background Images */
body::before {
  content: url("./images/morning_bg.png");
  content: url("./images/day_bg.png");
  content: url("./images/midday_bg.png");
  content: url("./images/afternoon_bg.png");
  content: url("./images/evening_bg.png");
  content: url("./images/goodnight_bg.png");
  display: none;
}
~ The greatest achievement in life is to inspire ~
Regards Stoker
User avatar
cabot
Jr. Style Validator
Posts: 1028
Joined: Sat Jan 07, 2012 4:16 pm

Re: CSS Preload images?

Post by cabot »

Hello,

It all depends on the context.
Are these images displayed when an element is hovered? (using a sprite would do the job)
Are they displayed regularly and randomly?
Are they heavy?

Preloading can be useful, but you need to bear in mind that you will be preloading all the images, and therefore consuming resources.

What's more, there are several ways of preloading images, so please take a look at this article.

I don't know if your request concerns the images displayed in the background of your header, but you can start by converting them to webp and compressing them with a tool like TinyPNG.

Original jpg (37.8 Ko):
Image

Convert to webp (28.4 Ko):
Image

Compressed webp (4.5 Ko):
The weight has become ridiculous and preloading would have no impact, or really imperceptible.
Image
User avatar
Stoker 4.0
Registered User
Posts: 1660
Joined: Sun Feb 13, 2011 1:33 pm
Location: Funen, Denmark
Name: Ulrik Christensen

Re: CSS Preload images?

Post by Stoker 4.0 »

So converting to compressed is a better choice.
And yes, its for the header images
~ The greatest achievement in life is to inspire ~
Regards Stoker
User avatar
Stoker 4.0
Registered User
Posts: 1660
Joined: Sun Feb 13, 2011 1:33 pm
Location: Funen, Denmark
Name: Ulrik Christensen

Re: CSS Preload images?

Post by Stoker 4.0 »

or AVIF
~ The greatest achievement in life is to inspire ~
Regards Stoker
User avatar
cabot
Jr. Style Validator
Posts: 1028
Joined: Sat Jan 07, 2012 4:16 pm

Re: CSS Preload images?

Post by cabot »

Yup :)

Edit: You've converted your images to webp, but you can also compress them with TinyPNG.
Depending on the number of colors, you can divide the final weight by 2, 3 or more.
Like the image in my last post. ^^

Return to “[3.3.x] Styles Support & Discussion”