Thursday, 15 April 2010

wordpress - Everyone is installing jQuery library on my site -



wordpress - Everyone is installing jQuery library on my site -

i using wordpress, comes built-in jquery library. when install plugin, version gets way in. larn write own code, tutorial asks me install one!

at time of writing, have 4-5 versions of jquery library installed!

it's going crazy! , don't think need many, need latest 1 google cdn best performance, set line in php file, didn't seem show anywhere after cleared cache.

function mytheme_jquery_enqueue(){ if(!is_admin()){ wp_deregister_script('jquery'); wp_register_script('jquery', "http" . ($_server['server_port'] == 443 ? "s" : "") . "://ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js", false, null); wp_enqueue_script('jquery'); } } add_action('wp_enqueue_scripts', 'mytheme_jquery_enqueue');

how prepare , rid of every other unnecessary version?

first, seek give hook lower priority, e.g.:

add_action( 'wp_enqueue_scripts', 'mytheme_jquery_enqueue', 99999 );

this way, it'll latest run, unless plugin has priority of 9999999... it's horse race...

then, enqueuing jquery in plug-ins

if code (or theme's code) unregistering jquery , re-registering location (google), need add together somewhere:

jquery.noconflict();

this makes jquery cooperate other scripts (i.e. prototype) seek define $ variable globally. wordpress has line bundled version, google not.

but, improve enqueuing cdn yourself, it's recommended utilize plugin: use google libraries. according core developer:

please not utilize method include jquery script google. above doesn't work , cause conflicts other scripts, along other issues. utilize "use google libraries" plugin instead, if want utilize google hosted versions of libraries. plugin right, , updated often. method above work superficially, cause problems downwards line. – otto jul 29 '12 @ 15:57

then, have issue not recommended load other jquery libraries , utilize 1 bundled wordpress. in case, should utilize remove_action, wp_deregister_script or wp_dequeue_script prevent plugins or theme load versions.

don’t dequeue wordpress’ jquery

as moderator on wordpress stack exchange, end spending lot of time on site. see lots of great questions, lots of not-so-great questions, , several you’ve-got-to-be-kidding-me questions. question see frustrates me:

how remove wordpress’ jquery , utilize google’s cdn version instead?

i have no problem saying that, if you’re asking question, have no business building website in first place.

jquery wordpress

No comments:

Post a Comment