admin管理员组

文章数量:1404923

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 !

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 !

Share Improve this question asked Jan 2, 2020 at 15:56 Pedro FerreiraPedro Ferreira 1791 silver badge10 bronze badges 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 Commented Jan 2, 2020 at 15:58
  • the option 1 was used in the footer.php – Pedro Ferreira Commented 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 Commented Jan 2, 2020 at 16:25
Add a comment  | 

1 Answer 1

Reset to default 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.

本文标签: performanceWordress importing scripts