Complete Guide to Enabling Gzip Compression for WordPress on Sina App Engine (SAE)
After migrating WordPress to Sina App Engine (SAE), your site's stability and speed are typically well-supported. For WordPress blogs deployed on SAE, enabling Gzip compression can significantly improve page load times and effectively reduce traffic consumption (Cloud Beans), thereby saving costs.
Testing shows SAE already enables Gzip compression for some static resources by default. However, you can further customize compression rules via the backend's "Page Compression" configuration. Since WordPress typically uses pseudo-static links, its article pages (dynamic content) are not automatically compressed by SAE. This guide details how to achieve site-wide Gzip compression through SAE backend configuration and WordPress code modification.
Step 1: Configure Page Compression in SAE Backend
- Log into the SAE Management Console and select your application.
- Navigate to the "AppConfig" page.
- Find and enter the "Page Compression" module, then verify with your security password.
- In the "Compress by File Type" settings, add all file types you wish to compress (e.g.,
.html,.php,.css,.js). - Also, configure "Compress by Content Length." For example, set it to compress content larger than 10240 bytes (10KB). This helps optimize compression efficiency.
Note: After this step, typically only static files (like CSS, JS, images) will be compressed. WordPress dynamic pages may still not be affected.
Step 2: Modify WordPress to Enable PHP Output Compression
Since WordPress dynamic pages are generated by PHP, you need to enable output buffering compression at the code level.
- Using SVN or SAE's code management, open the
index.phpfile in your WordPress root directory. - Find this line:
define('WP_USE_THEMES', true); - Add the following code immediately after that line:
ob_start('ob_gzhandler'); - Save the file and deploy to SAE.
This code starts PHP's output buffer before the theme loads and uses the ob_gzhandler callback function to apply Gzip compression to the output.
Verifying Compression
After completing both steps, use an online tool (like the Gzip detection tool from Chinaz) to test any page on your site. Successful compression typically achieves a 70%-85% reduction. For example, a 100KB page might compress to around 20KB, greatly improving load speed and saving traffic.
Common Issues & Notes
- Compression not working? Ensure both configuration steps are correctly completed. Clear your browser and SAE's CDN cache before retesting.
- Code placement: The line must be added after
define('WP_USE_THEMES', true);to ensure compression is enabled before theme rendering. - Compatibility: Most modern browsers support Gzip compression; compatibility is not a concern.
- SAE Environment: This guide is based on SAE's classic environment. Configuration may differ for other environments or cloud services.
By combining SAE's platform configuration with WordPress code-level optimization, you can easily enable site-wide Gzip compression for your blog, optimizing both speed and cost.