0

I am fairly new to Wordpress theme development, and I'm trying to structure my code using the best practices possible In your opinion whats the better option to import javascript files:

OPTION 1

<script src="<?php bloginfo('template_url'); ?>/js/anime.min.js"></script

OPTION 2

 wp_enqueue_script('some_script(s)');

in terms of loading time ?

Thanks in advance !

3
  • Where in the page are you putting option 1? That's likely the only difference in load time, as option 2 will also generate a script tag but put it at the end of the page by default.
    – Rup
    Jan 2, 2020 at 15:58
  • the option 1 was used in the footer.php Jan 2, 2020 at 16:24
  • Then they should be equivalent. wp_enqueue_script will generate script tags where your footer.php calls wp_footer.
    – Rup
    Jan 2, 2020 at 16:25

1 Answer 1

2

Option 2. Option 1 is just flat out incorrect, not a valid alternative. The proper methods for loading CSS and JavaScript in WordPress are documented here. Also, there's no meaningful performance difference between the two.

5
  • Okay, thank you Jan 2, 2020 at 16:24
  • wp_enqueue script is only loading the first script file is that normal ??? Jan 2, 2020 at 16:51
  • I'm using it like this ` wp_enqueue_script('script', get_stylesheet_directory_uri() . '/js/anime.min.js', false, '3.1.0');` for like 4 javascript files but only the first one is being loaded Jan 2, 2020 at 16:54
  • 1
    Did you give them unique names? Please read the documentation I linked. Jan 2, 2020 at 17:22
  • Yes fixed it after reading it ;) Jan 3, 2020 at 10:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.