Defer loading of javascript

Home Forums Main Forum Theme Suggestion Box Defer loading of javascript

This topic contains 6 replies, has 16 voices, and was last updated by  Lars Hærvig 3 years, 4 months ago.

Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • #17381

    Lars Hærvig
    Member

    The themes loads a lot of javascripts during initial page loading. If defering load to efter “document loaded” page load time will improve significantly (according to GTmetrix)

    How to do that?

    I would like that, because my page loads quite slow. 🙂

    #22901

    Sushil Adhikari
    Moderator

    Hi Lars Hærvig,

    Could you provide us your site URL, so we can provide you the exact solution.Most probably on all our theme, custom js are loaded after page load.

    We looks forward for your response.

    Thanks

    #22902

    Lars Hærvig
    Member

    Hi,

    Some more information:

    Site: nedikroppen.dk

    Thank you
    Lars

    #22904

    Lars Hærvig
    Member

    File upload failed – trying again

    Skrmbillede2016-05-1707.52.34.jpg
    Skrmbillede2016-05-1707.59.10.jpg

    Attachments:
    You must be logged in to view attached files.
    #22909

    Sushil Adhikari
    Moderator

    Hi there,

    Thanks for illustrating issue on details. All our .js are loaded on footer area which means js are loaded after the page loads. You can see the screenshot attached.

    And there is some text that are loaded outside the footer area. It also includes js from google analytics plugin. There is some js on theme that are loaded ourside the footer area. To load them on footer you can use this concept.

    wp_enqueue_script( 'puresimple-jquery-ui', get_template_directory_uri() . '/js/jquery-ui.js', array( 'jquery' )); 

    In the above code if add argument true at last it will load that particular js on footer for an example:

    wp_enqueue_script( 'puresimple-jquery-ui', get_template_directory_uri() . '/js/jquery-ui.js', array( 'jquery' ), true);

    Note: Please follow the process only if you are technically sound on WordP1ress.

    Thanks
    nedi-screenshot.jpg

    Attachments:
    You must be logged in to view attached files.
    #22929

    Lars Hærvig
    Member

    Thanks,

    I’m comfortable with programming (PHP) but not that skilled in WP yet.

    Where to put the code?

    Regards
    Lars

    #17382

    Sushil Adhikari
    Moderator

    Hi there,

    For now you can make changes on core file, later on theme update we will make this things available.

    Their on functions.php file you can find puresimple_scripts() function and their you can find whole js that are added on theme. For an example:

    wp_enqueue_script( 'puresimple-jquery-ui', get_template_directory_uri() . '/js/jquery-ui.js', array( 'jquery' ), '1.0',TRUE);

    You can take this article to know more on wp_enqueue_script function :
    https://developer.wordpress.org/reference/functions/wp_enqueue_script/

    We hope this will help you.

    Thanks

Viewing 7 posts - 1 through 7 (of 7 total)

You must be logged in to reply to this topic.