PHP Developers Network

A community of PHP developers offering assistance, advice, discussion, and friendship.
 
Loading
It is currently Thu Dec 14, 2017 7:42 pm

All times are UTC - 5 hours




Post new topic Reply to topic  [ 1 post ] 
Author Message
 Post subject: defer="defer"
PostPosted: Mon Oct 30, 2017 2:37 pm 
Offline
Forum Contributor

Joined: Fri Sep 05, 2008 3:34 pm
Posts: 491
Location: Victoria, BC
I was wondering for all the JaveScript in wordpress I was thinking why not load them all asynchronously so that Chome etc can grab all the parts at once and perk up rendering the site faster?

The idea is the have: <script defer="defer" src="myscript.js> which will load in parallel.

Now PHP can so some work such as: return str_replace( ' src', ' defer="defer" src', $tag );

Now some scripts already have defer, so I was wondering, a duplicate should be OK but to be smart, should I not check first?

Not sure the best spot yet to install my idea, thoughts? Found this code on https://wordpress.stackexchange.com/que ... 8335#38335

Syntax: [ Download ] [ Hide ]
add_filter( 'script_loader_tag', function ( $tag, $handle ) {

    if ( 'contact-form-7' !== $handle )
        return $tag;

    return str_replace( ' src', ' defer="defer" src', $tag );
}, 10, 2 );
 

_________________
Hardcore Games Legendary is the Only Way to Play!
Vegan Advocate 16 lbs grain to make only 1 lb meat, water for 6 months of showers and 34.1 lbs carbon dioxide
My sites are made with WordPress, which is a content management system, Joomla and Drupal are some alternatives


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 1 post ] 

All times are UTC - 5 hours


Who is online

Users browsing this forum: Google [Bot], Majestic-12 [Bot] and 11 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
Powered by phpBB® Forum Software © phpBB Group