SG Optimizer

外掛說明

這個外掛設計用來將 WordPress 網站連結至 SiteGround Performance 服務,因此它無法執行於其他主機服務提供商。

SG Optimizer 外掛包含多項處理指定效能最佳化的功能。

外掛相關設定

如需進一步瞭解這個外掛的運作方式,請參閱 SG Optimizer 教學課程

SuperCacher 設定

在這個分頁中,網站管理員可以為動態快取及 Memcached 分散式快取進行組態。在使用這個外掛前,請先確認已先在 cPanel 中啟用這兩項功能。如果相關快取功能運作正常,網站管理員便可以啟用/停用快取自動清理、排除不進行快取的網址並進行測試。

主機環境最佳化

在這個分頁中,網站管理員可為網站強制啟用 HTTPS、在不同的 PHP 版本間進行切換 (提供相容性檢查功能),並能為網站啟用或停用 Gzip 壓縮及瀏覽器快取規則。

網站前端最佳化

在這個分頁中,網站管理員可以啟用或停用網站上的 HTML、JS 及 CSS 資源的最小化/壓縮,以及從網站靜態資源中移除 Emoji 表情符號支援及查詢字串。

圖片最佳化

在這個分頁中,網站管理員可以啟用或停用對新上傳圖片的最佳化功能、批次最佳化已上傳的圖片,並對網站圖片啟用延遲載入。

外掛相容性

如果開發的外掛無法觸發 WordPress 標準勾點,或開發的外掛需要 SG Optimizer 清除快取,外掛開發者可以在程式碼中使用以下公開函式:

if (function_exists('sg_cachepress_purge_cache')) {
    sg_cachepress_purge_cache();
}

更棒的是,網站管理員可以將網址傳遞至函式,便能清理指定快取,而非清理全站快取。範例程式碼如下:

if (function_exists('sg_cachepress_purge_cache')) {
    sg_cachepress_purge_cache('https://yoursite.com/pluginpage');
}

網站管理員可以使用針對性設計的篩選器,從合併及最小化/壓縮中排除樣式。以下是範例程式碼,網站管理員可以將這些程式碼加入佈景主題的 functions.php 檔案中:

add_filter( 'sgo_css_combine_exclude', 'css_combine_exclude' );
function css_combine_exclude( $exclude_list ) {
    // Add the style handle to exclude list.
    $exclude_list[] = 'style-handle';
    $exclude_list[] = 'style-handle-2';

    return $exclude_list;
}

add_filter( 'sgo_css_minify_exclude', 'css_minify_exclude' );
function css_minify_exclude( $exclude_list ) {
    // Add the style handle to exclude list.
    $exclude_list[] = 'style-handle';
    $exclude_list[] = 'style-handle-2';

    return $exclude_list;
}

網站管理員可以使用針對性設計的篩選器,從最小化/壓縮中排除指令碼。以下是範例程式碼,網站管理員可以將這些程式碼加入佈景主題的 functions.php 檔案中:

add_filter( 'sgo_js_minify_exclude', 'js_minify_exclude' );
function js_minify_exclude( $exclude_list ) {
    $exclude_list[] = 'script-handle';
    $exclude_list[] = 'script-handle-2';

    return $exclude_list;
}

網站管理員可以使用針對性設計的篩選器,從非同步載入中排除指令碼。以下是範例程式碼,網站管理員可以將這些程式碼加入佈景主題的 functions.php 檔案中:

add_filter( 'sgo_js_async_exclude', 'js_async_exclude' );
function js_async_exclude( $exclude_list ) {
    $exclude_list[] = 'script-handle';
    $exclude_list[] = 'script-handle-2';

    return $exclude_list;
}

網站管理員可以使用以下篩選器,藉以排除網址獲包含指定查詢參數的網址:

add_filter( 'sgo_html_minify_exclude_params', 'html_minify_exclude_params' );
function html_minify_exclude_params( $exclude_params ) {
    // Add the query params that you want to exclude.
    $exclude_params[] = 'test';

    return $exclude_params;
}

add_filter( 'sgo_html_minify_exclude_urls', 'html_minify_exclude' );
function html_minify_exclude( $exclude_urls ) {
    // Add the url that you want to exclude.
    $exclude_urls[] = 'http://mydomain.com/page-slug';

    return $exclude_urls;
}

網站管理員可以使用以下篩選器,藉以在延遲載入中排除指定類別的圖片:

add_filter( 'sgo_lazy_load_exclude_classes', 'exclude_images_with_specific_class' );
function exclude_images_with_specific_class( $classes ) {
    // Add the class name that you want to exclude from lazy load.
    $classes[] = 'test-class';

    return $classes;
}

支援 WP-CLI

這個外掛從 5.0 版開始,便為全部選項及功能新增了完整的 WP-CLI 支援。

  • wp sg purge (url):清除全站快取或指定網址的快取
  • wp sg memcached enable|disable:啟用或停用 Memcached 分散式快取
  • wp sg forcehttps enable|disable:啟用或停用網站的 HTTPS
  • wp sg phpver check (–version=):檢查網站與 PHP 7.1 或指定版本的相容性
  • wp sg optimize:啟用或停用網站不同的最佳化設定 (列舉如下)
  • wp sg optimize html enable|disable:啟用或停用 HTML 最小化/壓縮
  • wp sg optimize js enable|disable:啟用或停用 JS 最小化/壓縮
  • wp sg optimize css enable|disable:啟用或停用 CSS 最小化/壓縮
  • wp sg optimize querystring enable|disable:啟用或停用移除查詢字串
  • wp sg optimize emojis enable|disable:啟用或停用移除 Emoji 表情符號指令碼
  • wp sg optimize images enable|disable:啟用或停用對新圖片的最佳化
  • wp sg optimize lazyload enable|disable:啟用或停用圖片的延遲載入
  • wp sg optimize gzip enable|disable:啟用或停用網站的 Gzip 壓縮功能
  • wp sg optimize browsercache enable|disable:啟用或停用瀏覽器快取規則
  • wp sg optimize dynamic-cache enable|disable:啟用或停用動態快取規則
  • wp sg optimize google-fonts enable|disable:啟用或停用 Google Fonts 字型組合
  • wp sg status dynamic-cache|autoflush-cache|mobile-cache|html|js|js-async|css|combine-css|querystring|emojis|images|lazyload_images|lazyload_gravatars|lazyload_thumbnails|lazyload_responsive|lazyload_textwidgets|gzip|browser-caching|memcache|ssl|ssl-fix|google-fonts:傳回最佳化目前狀態 (已啟用|已停用)

環境需求

要讓這個外掛正確執行,網站伺服器必須滿足以下條件:

  • SiteGround 帳號
  • WordPress 4.7 或更新版本
  • PHP 5.5 或更新版本
  • 由於這個外掛依賴特定的伺服器組態,如果網站主機並未託管於 SiteGround,外掛便會無法執行

這個外掛為確保正常執行而使用了 Cookie,但不會儲存個人資料,外掛僅用於符合我們的快取系統需求。

螢幕擷圖

  • 在 [SuperCacher 設定] 分頁中,網站管理員可以處理動態快取及 Memcached 分散式快取。網站管理員可以在這裡排除外掛的 URI,並手動清除動態快取
  • 在 [主機環境最佳化] 分頁中,網站管理員可以為網站強制使用 HTTPS 通訊協定,切換 PHP 版本並啟用 Gzip 及瀏覽器快取規則
  • 在 [網站前端最佳化] 分頁中,網站管理員可以將 HTML、CSS 及 JS 進行最小化/壓縮,並能從網站的靜態資源中移除查詢字串並停用 Emoji 表情符號支援
  • 在 [圖片最佳化] 分頁中,網站管理員能為媒體庫中的圖片進行最佳化,並能為網站加入延遲載入功能
  • 多站網路專屬功能:在 [全域設定] 分頁中,多站網路管理員能為整個多站網路的全部設定進行全域組態
  • 多站網路專屬功能:在 [個別網站預設值] 分頁中,多站網路管理員可以為將來加入多站網路的新網站設定最佳化預設設定

安裝方式

自動安裝

  1. 前往 [外掛]→[安裝外掛]。
  2. 搜尋「SG Optimizer」。
  3. 點擊外掛名稱 SG Optimizer 旁的 [立即安裝] 按鈕。
  4. 外掛安裝完畢後,請點擊 [啟用]。

手動安裝

  1. 登入 WordPress 網站管理面板,並前往 [外掛]→[安裝外掛]。
  2. 點擊 [上傳外掛] 按鈕。
  3. 點擊 [選擇檔案] 按鈕,並瀏覽至已下載的外掛安裝套件 sg-cachepress.zip
  4. 點擊 [立即安裝] 按鈕。
  5. 前往 [外掛]→[已安裝的外掛],點擊 SG Optimizer 外掛的 [啟用] 連結。

使用者評論

2020 年 4 月 2 日
Siteground just keeps getting better. For an economy design/developer the hosting, tools and services provided by Siteground are outstanding.
2020 年 4 月 2 日
It allows you to enable services like lazy loading, image optimising and testing page speed right from your site. Excellent plugin from Siteground.
2020 年 3 月 31 日
I don't know why I never started using this earlier. I think all my sites should be hosted on Siteground.
閱讀全部 280 則使用者評論

參與者及開發者

以下人員參與了開源軟體〈SG Optimizer〉的開發相關工作。

參與者

SG Optimizer 外掛目前已有 11 個本地化語言版本。 感謝全部譯者為這個外掛做出的貢獻。

將 SG Optimizer 外掛本地化為台灣繁體中文版

對開發相關資訊感興趣?

任何人均可瀏覽程式碼、查看 SVN 存放庫,或透過 RSS 訂閱開發記錄

變更記錄

Version 5.4.6

  • Improved compatibility with page builders
  • Improved compatibility with latest Elementor
  • Added support for popular AMP plugins
  • Better WebP optiomization status reporting

Version 5.4.5

  • Improved elementor support
  • Improved flothemes support
  • Improved handling of @imports in combine css

Version 5.4.4

  • Improved transients handling
  • Added Jet Popup support

Version 5.4.3

  • Added Lazy loading functionality for iframes
  • Added Lazy loading functionality for videos

Version 5.4.2

  • Fixed bug with WebP image regeneration on image delete

Version 5.4.1

  • Added PHP 7.4 support for PHP Compatibility Checker
  • Improved WebP Conversion
  • Fixed bug with WebP image regeneration on image edit
  • Improved plugin localization

Version 5.4.0

  • Added WebP Support on All Accounts on Site Tools
  • Added Google PageSpeed Test
  • Improved Image Optimization Process
  • Improved SSL Certificate check

Version 5.3.10

  • Better PHP Version Management for Site Tools
  • NGINX Direct Delivery for Site Tools

Version 5.3.9

  • Improved check for SG Servers

Version 5.3.8

  • Fixed a bug when Memcached fails to purge when new WordPress version requiring a database update is released
  • Added alert and check if you’re running SG Optimizer on a host different than SiteGround
  • Improved compatibility with WooCommerce
  • Improved conditional styles combination
  • Improved image optimization process

Version 5.3.7

  • Added WooCommerce Square Payment & Braintree For WooCommerce Exclude by Default
  • Improved Google Fonts Optimization
  • Added Notice for Defer Render-Blocking Scripts Optimization
  • Added wp-cli commands for Google Fonts Optimization
  • Changed New Images Optimizer hook to wp_generate_attachment_metadata

Version 5.3.6

  • Improved Google Fonts loading with better caching
  • Improved Defer of render-blocking JS

Version 5.3.5

  • WordPress 5.3 Support Declared
  • Better Elementor Compatibility
  • Better Image Optimization Messaging
  • Better Google Fonts combination
  • Added PHP 7.4 support

Version 5.3.4

  • Improved Async load of JS files
  • Added Google Fonts Combination optimization
  • Moved lazyload script in footer
  • Improved CSS combination

Version 5.3.3

  • Improved browser cache handling upon plugin update
  • Added wp-cli commands for Dynamic Cache, Autoflush and Browser-Speciffic cache handling

Version 5.3.2

  • Fixed bug with https enforce for www websites
  • Improved JILT support

Version 5.3.1

  • Better SSL force to accommodate websites with WWW in the URL
  • Global exclusion of siteorigin-widget-icon-font-fontawesome from Combine CSS

Version 5.3.0

  • Refactoring of the Lazy Load functionality
  • Redesign of the Lazy Load screen
  • Improved WooCommerce product image Lazy Load
  • Gzip functionality update for Site Tools accounts
  • Browser caching functionality update for Site Tools accounts
  • Improved Browser caching functionality for cPanel accounts

Version 5.2.5

  • New Feature: Option to split caches per User Agent
  • New Feature: Option to disable lazy loading for mobile devices
  • Improved Memcached check

Version 5.2.4

  • Improved XML RCP checks compatibility

Version 5.2.3

  • Improved LazyLoad

Version 5.2.2

  • Improved Events Calendar Compatibility
  • Suppressed notices in the REST API in certain cases
  • Improved nonscript tag in LazyLoad

Version 5.2.1

  • Improved Cloudflare compatibility

Version 5.2.0

  • Exclude list Interface for JavaScript handlers
  • Exclude list Interface for CSS handlers
  • Exclude list Interface for HTML minification (URL like dynamic)
  • Exclude list interface for LazyLoading (Class)
  • Improved Thrive Architect support
  • Fixed notice when purging comment cache

Version 5.1.3

  • Improved Elementor support
  • Improved CSS optimization for inclusions without protocol
  • Excluded large PNGs from optimizations
  • Added better WP-CLI command documentation

Version 5.1.2

  • Added support for Recommended by SiteGround PHP Version
  • Improved LazyLoad Support for WooCommerce sites
  • Improved Image Optimization checks
  • Improved PHP Version switching checks
  • Added wp cli status command for checking optimization status
  • Fixed bug with Combine CSS

Version 5.1.1

  • Improved cache invalidation for combined styles
  • Cache purge from the admin bar now handles combined files too
  • Added filter to exclude images from Lazy Loading
  • Added filter to exclude pages from HTML Minification
  • Added Filter to query params from HTML Minification
  • Added PHP 7.3 support

Version 5.1.0

  • Added CSS Combination Functionality
  • Added Async Load of Render-Blocking JS
  • Added WooCommerce Support for LazyLoad
  • Added Filter to Exclude Styles from CSS Combination
  • Improved Lazy Load Functionality on Mobile Devices
  • Fixed Issue with WP Rocket’s .htaccess rules and GZIP
  • Fixed Issue with Query String Removal Script in the Admin Section
  • Fixed Compatibility Issues with 3rd Party Plugins and Lazy Load
  • Fixed Compatibility Issues with Woo PDF Catalog Plugin and HTML Minification
  • Improved Memcached Reliability
  • Improved Lazy Load for Responsive Images

Version 5.0.13

  • Modified HTML minification to keep comments
  • Interface Improvements
  • Better input validation and sanitation for PHP Version check
  • Improved security

Version 5.0.12

  • Better cache purge for multisite
  • Surpress dynamic cache notices for localhost sites

Version 5.0.11

  • Improved handling of third party plugins causing issues with the compatibility checker functionality
  • Optimized WP-CLI commands for better performance
  • Better notice handling for Multisite and conflicting plugins

Version 5.0.10

  • Fixed issue with Mythemeshop themes
  • Fixed issues with exclude URL on update
  • Fixed issues with exclude URL on update
  • Exclude Lazy Load from AMP pages
  • Exclude Lazy Load from Backend pages
  • Fixed WPML problems
  • Fixed Beaver Builder issues
  • Fixed Spanish translations
  • Fixed incompatibility with JCH Optimize

Version 5.0.9

  • Fixed woocommerce bugs
  • Improved memcached flush
  • Improved https force

Version 5.0.8

  • Better .htaccess handling when disabling and enabling Browser Cache and Gzip
  • Improved image optimization handling
  • Added option to stop the image optimization and resume it later
  • Fixed bug with memcached notifications
  • Fixed bug with conflicting plugin notices for non-admins
  • Fixed bug when user accesses their site through IP/~cPaneluser
  • Fixed bug with labels for HTML, CSS & JS Minification
  • SEO Improvements in the Lazy Load functionality

Version 5.0.7

  • Fixed bug with notifications removal
  • Fixed bug with modifying wrong .htaccess file for installations in subdirectory
  • Flush redux cache when updating to new version
  • Improved check for existing SSL rules in your .htaccess file
  • Added check and removal of duplicate Gzip rules in your .htaccess file
  • Added check and removal of duplicate Browser caching rules in your .htaccess file

Version 5.0.6

  • Memcache issues fixed. Unique WP_CACHE_KEY_SALT is generated each time you enable it on your site.
  • Better status update handling
  • Added option to start checks even if the default WP Cron is disabled (in case you use real cronjob)

Version 5.0.5

  • Fixed Compatibility Checker progress issues.
  • Fixed images optimization endless loops.
  • Changed php version regex to handle rules from other plugins.

Version 5.0.4

  • Fixed CSS minification issues.
  • Add option to re-optimize images.
  • Allow users to hide notices.

Version 5.0.0

  • Complete plugin refactoring
  • Frontend optimiztions added
  • Environment optimizations added
  • Images Optimizatoins adder
  • Full WP-CLI Support
  • Better Multisite Support
  • Better Interface

Version 4.0.7

  • Fixed bug in the force SSL functionality in certain cases for MS
  • Added information about the cookie our plugin uses in the readme file

Version 4.0.6

  • Bug fixes
  • Better https enforcement in MS environment

Version 4.0.5

  • Removed stopping of WP Rocket cache

Version 4.0.4

  • Minor bug fixes

Version 4.0.3

  • Switching recommended PHP Version to 7.1

Version 4.0.2

  • WPML and Memcache / Memcached bug fix

Version 4.0.1

  • Minor bug fixes
  • UK locale issue fixed

Version 4.0.0

  • Added proper Multisite support
  • Quick optimizations – Gzip and Browser cache config settings for the Network Admin
  • Network admin can purge the cache per site
  • Network admin can disallow Cache and HTTPS configuration pages per site
  • WPML support when Memcached is enabled
  • Cache is being purged per site and not for the entire network
  • Multiple performance & interface improvements
  • Security fixes against, additional access checks introduced
  • Fixed minor cosmetic errors in the interface

Version 3.3.3

  • Fixed minor interface issues

Version 3.3.2

  • Fixed bug with disabling the Force HTTPS option

Version 3.3.1

  • Fixed cache purge issue when CloudFlare is enabled
  • Added logging of failed attempts in XMLRPC API.

Version 3.3.0

  • Improved public purge function for theme and plugin developers
  • Added WP-CLI command for cache purge – wp sg purge

Version 3.2.4

  • Updated Memcache.tpl
  • Fixed a link in the PHP Check interface

Version 3.2.3

  • Improved WP-CLI compatibility

Version 3.2.1

  • Improved cron fallback, added error message if the WP CRON is disabled

Version 3.2.0

  • Adding PHP 7.0 Compatibility check & PHP Version switch

Version 3.0.5

  • Improved Certficiate check

Version 3.0.4

  • Fixed bug with unwrittable .htaccess

Version 3.0.3

  • Fixed bug in adding CSS files

Version 3.0.2

  • User-agent added to the SSL availability check

Version 3.0.1

  • PHP Compatibility fixes

Version 3.0.0

  • Plugin renamed to SG Optimizer
  • Interface split into multiple screens
  • HTTPS Force functionality added which will reconfigure WordPress, make an .htaccess redirect to force all the traffic through HTTPS and fixes any potential insecure content issues
  • Plugin prepared for PHP version compatibility checker and changer tool

Version 2.3.11

  • Added public purge function
  • Memcached bug fixes

Version 2.3.10

  • Improved Memcached performance
  • Memcached bug fixes

Version 2.3.9

  • Improved WordPress 4.6 compatibilitty

Version 2.3.8

  • Improved compatibility with SiteGround Staging System

Version 2.3.7

  • Fixed PHP warnings in Object Cache classes

Version 2.3.6

  • Minor URL handling bug fixes

Version 2.3.5

  • Improved cache testing URL detection

Version 2.3.4

  • CSS Bug fixes

Version 2.3.3

  • Improved Memcache work
  • Interface improvements
  • Bug fixes

Version 2.3.2

  • Fixed bug with Memcached cache purge

Version 2.3.1

  • Interface improventes
  • Internationalization support added
  • Spanish translation added by SiteGround.es
  • Bulgarian translation added

Version 2.3.0

  • Memcached support added
  • Better PHP7 compatibility

Version 2.2.11

  • Improved compatibility with WP Rocket
  • Bug fixes

Version 2.2.10

  • Revamped notices work
  • Bug fixes

Version 2.2.9

  • Bug fixes

Version 2.2.8

  • Bug fixing and improved notification behaviour
  • Fixed issues with MS installations

Version 2.2.7

  • Added testing box and notification if Dynamic Cache is not enabled in cPanel

Version 2.2.6

  • Fixed bug with Memcached causing issues after WP Database update

Version 2.2.5

  • Minor system improvements

Version 2.2.4

  • Minor system improvements

Version 2.2.3

  • Admin bar link visible only for admin users

Version 2.2.2

  • Minor bug fixes

Version 2.2.1

  • Added Purge SG Cache button
  • Redesigned mobile-friendly interface

Version 2.2.0

  • Added NGINX support

Version 2.1.7

  • Fixed plugin activation bug

Version 2.1.6

  • The purge button will now clear the Static cache even if Dynamic cache is not enabled
  • Better and more clear button labeling

Version 2.1.5

  • Better plugin activation and added to the wordpress.org repo

Version 2.1.2

  • Fixed bug that prevents you from enabling Memcached if using a wildcard SSL Certificate

Version 2.1.1

  • Cache will flush when scheduled posts become live

Version 2.1.0

  • Cache will be purged if WordPress autoupdates

Version 2.0.3

  • Minor bug fixes

Version 2.0.2

  • 3.8 support added

Version 2.0.1

  • Interface improvements
  • Minor bug fixes

Version 2.0

  • New interface
  • Minor bug fixes
  • Settings and Purge pages combined into one

Version 1.2.3

  • Minor bug fixes
  • SiteGround Memcached support added
  • URL Exclude from caching list added

1.0

  • Plugin created.