Deferring JavaScript

Creating and modifying plugins.
Post Reply
HiCotN
Regular
Posts: 37
Joined: Sat Aug 05, 2006 8:12 am

Deferring JavaScript

Post by HiCotN » Thu Apr 27, 2017 4:06 am

Is there currently a way to defer the javascript for the Lightbox plugin? If not, would it be hard to implement?

User avatar
yellowled
Regular
Posts: 6906
Joined: Fri Jan 13, 2006 12:46 pm
Location: Eutin, Germany
Contact:

Re: Deferring JavaScript

Post by yellowled » Thu Apr 27, 2017 1:34 pm

HiCotN wrote:Is there currently a way to defer the javascript for the Lightbox plugin? If not, would it be hard to implement?
Not sure what exactly you mean or what you are trying to achieve by this?

Technically, HTML5 offers the defer and aync attributes to optimize script loading, and it should be possible to add them as options to the plugin config. The “issue” is that this is a plugin.

By that I mean that it a) runs in very different settings (blogs, other plugins etc.) and b) includes multiple lightbox scripts that may or may not work well with to those attributes. So using these attributes should be optional and be decided by the user, not be a default setting.

It would need a developer to implement and (more importantly) test this, but it should not be hard to implement.

YL
amazon Wishlist - Serendipity-Podcast (German only, sorry)

HiCotN
Regular
Posts: 37
Joined: Sat Aug 05, 2006 8:12 am

Re: Deferring JavaScript

Post by HiCotN » Thu Apr 27, 2017 7:10 pm

Hi Yellowled!

Thank you for considering this. This came about via the PageSpeed test. We achieve 100% score for both mobile and desktop when the Lightbox plugin is set to inactive.

I will experiment with setting defer and/or async and see if I can get it to work.

HiCotN
Regular
Posts: 37
Joined: Sat Aug 05, 2006 8:12 am

Re: Deferring JavaScript

Post by HiCotN » Fri Oct 13, 2017 4:44 am

I have achieved what I was looking for. In the Lightbox plugin settings, I changed the option for "JavaScript Load optimization" to Yes.

The description could use work though. I'd be happy to help tidy these up. The English on some are fair.

Original description
"Switching this option on will load Lightbox' JavaScript and CSS only, if an image is shown on the current page. This may shorten the page loading time noticeable."

An easier to read version
"No" will load Lightbox's JavaScript and CSS all-the-time. "Yes" will only load Lightbox's JS and CSS if there are images on the current page. If there are no images, the JS and CSS won't load needlessly. This may be a great way to increase your site's speed.

thh
Regular
Posts: 210
Joined: Thu Oct 26, 2006 2:38 pm
Location: Stuttgart, Germany
Contact:

Re: Deferring JavaScript

Post by thh » Sun Oct 15, 2017 2:14 pm

Thanks for your suggestion.

I have opened a pull request at https://github.com/s9y/additional_plugins/pull/69 with a wording similar to what you suggested.

Post Reply