Wednesday 5 March 2014

Thay thế jquery.js và jquery-migrate.js tăng tốc độ Wordpress @ Top 10 Hosting

Thay thế jquery.js và jquery-migrate.js trong  tăng tốc độ load trang web.

Như các bạn biết trong phiên bản WordPress mới nhất luôn có 2 file là jquery.js và jquery-migrate.js. Việc dùng thư viện của bên thứ 3 để load 2 file này giúp giảm tải cho trang web, đỡ tốn bằng thông và giúp trang web load nhanh hơn. File jquery.js thì có sẵn trong thư viện của Google, còn file jquery-migrate thì chúng ta sẽ dùng trong thư viện của jquery.com.

Bài hướng dẫn này giúp bạn thay thế 2 file đó trong trường hợp dùng theme của Genesis/Studiopress.

Chỉ cần thêm đoạn code dưới đây vào dưới cùng của file functions.php


 


add_action( "wp_enqueue_scripts", "script_managment", 99);
/**
* Change the location of jQuery and jQuery-migrate.
*
* @author hostot.com
* @since 1.0.0
*/
function script_managment()
wp_deregister_script( "jquery" );
wp_deregister_script( "jquery-migrate" );
wp_register_script( "jquery", "http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js" );
wp_register_script( "jquery-migrate", "http://code.jquery.com/jquery-migrate-1.2.1.min.js" );
wp_enqueue_script( "jquery", "http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js" );
wp_enqueue_script( "jquery-migrate", "http://code.jquery.com/jquery-migrate-1.2.1.min.js" );


hostingadmin