Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

how to enqueue, defer or async javascript? Seems like it is moved to somewhere else #682

Open
internetpirate11 opened this issue Feb 4, 2021 · 2 comments
Labels
documentation Issue in documentation or videos

Comments

@internetpirate11
Copy link

Issue Overview

Well I am currently watching wp rig videos https://wprig.io/learn/enqueue-async-or-defer-javascript/ I see no code in functions.php files to change. Seems like it is moved to somewhere else. Can any one say me which file to edit to defer js

@internetpirate11
Copy link
Author

hello any reply?

@jacklowrie
Copy link

You can set async and defer on individual scripts when you enqueue them in components:

wp_enqueue_script(
    'wp-rig-new-script-name',
    get_theme_file_uri( '/assets/js/new-script-name.min.js' ),
    [],
    wp_rig()->get_asset_version( get_theme_file_path( '/assets/js/new-script-name.min.js' ) ),
    false
);
wp_script_add_data( 'wp-rig-new-script-name', 'defer', true );
// or wp_script_add_data( 'wp-rig-new-script-name', 'async', true );

is that what you mean?

@jacklowrie jacklowrie added the documentation Issue in documentation or videos label Feb 27, 2021
@jacklowrie jacklowrie moved this from To do to In progress in Documentation from Issues Feb 27, 2021
@jacklowrie jacklowrie moved this from In progress to Done (close/archive when published) in Documentation from Issues Mar 3, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Issue in documentation or videos
Projects
Documentation from Issues
  
Done (close/archive when published)
Development

No branches or pull requests

2 participants