{"id":609,"date":"2019-02-12T14:56:54","date_gmt":"2019-02-12T06:56:54","guid":{"rendered":"https:\/\/www.intelliwolf.com\/?p=609"},"modified":"2019-08-27T14:19:33","modified_gmt":"2019-08-27T06:19:33","slug":"stop-hidden-wordpress-image-loading-on-mobile","status":"publish","type":"post","link":"https:\/\/wordpress-757293-2559390.cloudwaysapps.com\/stop-hidden-wordpress-image-loading-on-mobile\/","title":{"rendered":"How To Stop A Hidden WordPress Image Loading On Mobile"},"content":{"rendered":"\n

One of our readers commented on the tutorial about responsively hiding elements in Elementor<\/a> raising a great question: what if you don't just want the element to be hidden - what if you wanted to prevent an image from even loading on mobile.<\/p>\n\n\n\n

With most methods of hiding elements for mobile, you're just assigning this code to the element:<\/p>\n\n\n\n

display: none;<\/code><\/pre>\n\n\n\n

That literally only stops the browser from displaying the element.<\/p>\n\n\n\n

The problem comes if you have a large image that you're trying to hide.<\/p>\n\n\n\n

The browser will still load the image. It just won't be seen. But it adds to the \"weight\" of the page and will negatively impact the page load speed.<\/p>\n\n\n\n

Here's what I mean:<\/p>\n\n\n\n

\"\"<\/figure><\/div>\n\n\n\n

See how the image above is not visible on a mobile size? I've circled where it appears on larger browser sizes.<\/p>\n\n\n\n

Now look at the bottom of the graphic where the files that are loaded are listed. That png is what's hidden.<\/p>\n\n\n\n

If you're just talking about a couple of kilobytes, that's no big deal.<\/p>\n\n\n\n

But if the hidden image is a megabyte or more, you probably shouldn't be loading that on mobile.<\/p>\n\n\n\n

Unfortunately, browser technology still has a way to go.<\/p>\n\n\n\n

To stop a hidden image loading on mobile (or any specific screen size), we need to get a little creative.<\/p>\n\n\n\n

Thankfully it's usually not too difficult to do in most page builders<\/a>.<\/p>\n\n\n\n

How to prevent a hidden WordPress image from loading on mobile:<\/strong><\/p>\n\n\n\n

  1. Create an area to hold the image<\/li>
  2. Set the image as a background image of that area<\/li>
  3. Set a parent of that area to \"display: none;\" on mobile<\/li><\/ol>\n\n\n\n

    See below for the steps in various page builders.<\/p>\n\n\n\n