Deprecated: ob_end_flush(): Producing output from user output handler ___wejns_wp_whitespace_fix is deprecated in /home/jesselin/blog.jesselin.com/wp-includes/functions.php on line 5493

Notice: Function _load_textdomain_just_in_time was called incorrectly. Translation loading for the jct-udc domain was triggered too early. This is usually an indicator for some code in the plugin or theme running too early. Translations should be loaded at the init action or later. Please see Debugging in WordPress for more information. (This message was added in version 6.7.0.) in /home/jesselin/blog.jesselin.com/wp-includes/functions.php on line 6170

Notice: Function _load_textdomain_just_in_time was called incorrectly. Translation loading for the health-check domain was triggered too early. This is usually an indicator for some code in the plugin or theme running too early. Translations should be loaded at the init action or later. Please see Debugging in WordPress for more information. (This message was added in version 6.7.0.) in /home/jesselin/blog.jesselin.com/wp-includes/functions.php on line 6170

Deprecated: ob_end_flush(): Producing output from user output handler LiteSpeed\Core::send_headers_force is deprecated in /home/jesselin/blog.jesselin.com/wp-includes/functions.php on line 5493

Deprecated: ob_end_flush(): Producing output from user output handler {closure:od_buffer_output():54} is deprecated in /home/jesselin/blog.jesselin.com/wp-includes/functions.php on line 5493
2026/06/05 依照有使用的區塊載入css - 這裡胡說 JL TALKS2026/06/05 依照有使用的區塊載入css - 這裡胡說 JL TALKS
AI架站日記

2026/06/05 依照有使用的區塊載入css

🛫空姐卡 常去日韓用這張最划算,一年份總量版,社群敲碗訂製產品
💺 傑西大叔 x 易遊網折扣碼:點擊網站專屬連結,全球機票1%【ezjessef1】全球訂房3%優惠【ezjesseh3】
日本購物折價券總整理(點這裡):BIC CAMERA、近鐵、大丸、松板屋、札幌藥妝
加入LINE社群『不在機場就在去機場的路上』 入群密碼『RCMQ(後方接任何一個台灣小吃)』
將本網站加入到 GOOGLE 偏好來源

Deprecated: preg_match(): Passing null to parameter #2 ($subject) of type string is deprecated in /home/jesselin/blog.jesselin.com/wp-includes/formatting.php on line 6246

Deprecated: preg_match(): Passing null to parameter #2 ($subject) of type string is deprecated in /home/jesselin/blog.jesselin.com/wp-includes/formatting.php on line 6246

這個功能核心很單純,就是把不需要使用到的css給移除,而且直接wordpress直接有內建這樣的功能,直要開啟就可以了。因為我的網站內容全部都是改以區塊編輯器進行編輯,所以也把荊典編輯器使用到的也移除。

這個功能加上去之後,我的所有前端效能也有一部份的提升。

1. 啟用區塊樣式按需載入 (Separate Block Assets Loading)

  • 相關程式碼:phpadd_filter(‘should_load_separate_core_block_assets’, ‘__return_true’);
  • 原理說明: 在預設情況下,WordPress 會將所有 Gutenberg 區塊編輯器 (Block Editor) 的核心區塊樣式打包成一個龐大的 CSS 檔案並在前端一次性載入(不論該頁面是否有使用到這些區塊)。 透過將 should_load_separate_core_block_assets 過濾器掛鉤 (Filter Hook) 設定為 true,可以強制 WordPress 啟用獨立按需載入機制。如此一來,系統只會針對目前頁面中實際存在的區塊去載入對應的 CSS 樣式,大幅降低了首頁或單一文章頁面的 CSS 檔案體積。

2. 移除經典主題編輯器預設樣式 (Dequeue Classic Theme Styles)

  • 相關程式碼:phpadd_action(‘wp_enqueue_scripts’, [$this, ‘remove_classic_theme_styles’], 20);public function remove_classic_theme_styles(): void { wp_dequeue_style(‘classic-theme-styles’);}
  • 原理說明: WordPress 為了相容傳統主題,預設會在前端載入一個名為 classic-theme-styles 的樣式表。對於已經完全使用區塊編輯器 (Block Editor) 的現代網站而言,這個樣式表是多餘且無用的。 本模組透過在 wp_enqueue_scripts 動作掛鉤 (Action Hook) 中使用 wp_dequeue_style() 函式,將此經典主題相容性 CSS 從佇列中移除,從而減少一個不必要的 HTTP 請求與 CSS 體積。

三、 效能優化成效分析

  1. 減少無用 CSS (Unused CSS):僅載入當前頁面所需的區塊樣式,能通過 Google PageSpeed Insights 等工具中「減少未使用的 CSS」檢測項目。
  2. 降低頁面阻塞時間 (Blocking Time):減少了瀏覽器在轉譯 (Rendering) 網頁前需要下載與解析的 CSS 總量,有助於縮短最大內容繪製 (Largest Contentful Paint, LCP) 與首次內容繪製 (First Contentful Paint, FCP) 的時間。
  3. 優化快取管理:搭配 LiteSpeed Cache 等快取外掛時,能讓產生的 HTML 結構與 CSS 載入更為乾淨,提升快取命中時的傳輸效率。

傑西大叔|專業航旅自媒體
骨子裡是理性的資訊人,靈魂裡裝著飛行的翅膀。擅長以理工腦的邏輯與數據,拆解複雜的航空事件與天氣分析,提供平心靜氣、綜觀全貌的飛行旅行決策建議。

飛行資歷: 累積 142 萬公里 / 繞行地球 34 圈 / 走訪 72 座機場 / 執飛 163 條航線
專注領域: 飛行體驗優化、機艙座位分析、CIQS 通關實戰
斜槓身分: 科技器材控、Podcast 製作人、堅持味蕾的吃貨
Back to top button