[WordPress] 外掛分享: WP HeadJS

首頁外掛目錄 › WP HeadJS
10+
安裝啟用
尚無評分
5033 天前
最後更新
問題解決
WordPress 2.9.1+ v0.1 上架:2012-06-16

內容簡介

這個外掛使用 wp_print_scripts 行動鉤子,而不是替代實現所使用的輸出緩衝和 regex。

這種方法的缺點是,只有通過 wp_enqueue_script 載入的腳本會受到該插件的影響,好處是避免在每個頁面加載時使用輸出緩衝以提高性能。

該插件將保留通過 wp_localize_script 添加的任何本地化,並使用傳遞給 wp_enqueue_script 的第一個參數作為 head.js 調用中腳本的標籤。例如,

wp_enqueue_script('jquery','https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js');

會顯示為

head.js({"jquery": "https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"});

這使您能夠在特定腳本準備就緒時運行回調,例如

head.ready('jquery',function(){
//當 jquery 加載時執行某些操作
});

有關 HeadJS 用法的更多信息,請參見 http://headjs.com/

外掛標籤

開發者團隊

⬇ 下載最新版 (v0.1) 或搜尋安裝

① 下載 ZIP → 後台「外掛 › 安裝外掛 › 上傳外掛」
② 後台搜尋「WP HeadJS」→ 直接安裝(推薦)

原文外掛簡介

This plugin uses the wp_print_scripts action hook, as opposed to output buffering and regex used by alternative implementations.
The downside of this method is that only scripts loaded via wp_enqueue_script will be affected by the plugin, the upside is better
performance by avoiding output buffering on every page load.
The plugin will preserve any localizations added via wp_localize_script, and uses the first parameter passed to wp_enqueue_script
as the label for the script in the head.js call. For example,
wp_enqueue_script('jquery', 'https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js');

would show up as
head.js({"jquery": "https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"});

This allows you to run callbacks when specific scripts are ready, such as
head.ready('jquery', function() {
//do something when jquery is loaded
});

For more on HeadJS usage, see http://headjs.com/

延伸相關外掛

文章
Filter
Apply Filters
Mastodon