You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

添加Expires Headers - GTmetrix检测:5个静态组件无远期过期日期

Fixing Expires Headers for Flagged External Resources

Alright, let's tackle that Expires Headers warning from GTmetrix. The 5 static components flagged are all external assets—Google Fonts stylesheets and a WordPress.com tracking pixel—and here's how to resolve each case:

First, let's recap the resources GTmetrix called out:

  • https://fonts.googleapis.com/css?family=Poppins%3A300%2Cregular%2C500%2C600%2C700%2Clatin-ext%2Clatin%2Cdevanagari&ver=1.0.0
  • https://fonts.googleapis.com/css?family=Poppins%3A700%2C300&ver=1581165984
  • https://fonts.googleapis.com/css?family=Poppins:700%2C300%2C400%7CRoboto:400%2C900
  • https://fonts.googleapis.com/css?family=Montserrat%3Aregular%2C700&ver=6.0.5
  • https://pixel.wp.com/g.gif?v=ext&j=1%3A8.1.1&blog=167300497&post=1633&tz=0&srv=alshuwaifatmarbles.com&host=alshuwaifatmarbles.com&ref=&fcp=2042&rand=0.1473167431208402

Since these are hosted outside your server, you can't directly edit their configs to add Expires Headers. Here are your actionable fixes:

1. Resolve Google Fonts Stylesheets

Google Fonts doesn't set long-enough cache headers on their CSS files, so we have two reliable workarounds:

Option A: Host Fonts Locally (Most Control)

By moving the fonts to your own server, you get full say over cache rules:

  1. Visit each Google Fonts CSS link in your browser, copy the @font-face rules, and download the corresponding .woff2/.ttf font files.
  2. Upload the font files to a folder in your WordPress theme (e.g., wp-content/themes/your-theme/fonts/).
  3. Replace the existing Google Fonts <link> tags in your theme with the local @font-face rules in your custom CSS.
  4. Add cache rules to your server config to set far-future Expires Headers:
    • For Apache (add to .htaccess):
      <IfModule mod_expires.c>
          ExpiresActive On
          # Cache fonts for 1 year
          ExpiresByType font/woff "access plus 1 year"
          ExpiresByType font/woff2 "access plus 1 year"
          ExpiresByType font/ttf "access plus 1 year"
      </IfModule>
      
    • For Nginx (add to your server block):
      location ~* \.(woff|woff2|ttf)$ {
          expires 1y;
          add_header Cache-Control "public, immutable";
      }
      

Option B: Cache via CDN

If you use a CDN like Cloudflare, create a rule to cache these Google Fonts resources. Most CDNs let you set a 1-year cache duration for third-party assets, which will add proper Expires Headers when the CDN serves the content to your visitors.

2. Handle the WordPress.com Tracking Pixel (pixel.wp.com/g.gif)

This is a third-party tracking asset, so you have two choices:

  • Disable it: If you don't need WordPress.com's stats, turn off this feature via your WordPress settings or use a plugin to remove the tracking code entirely. This eliminates the resource from loading at all.
  • Proxy it through your server: If you must keep it, set up a server proxy to fetch the pixel through your domain. This lets you add Expires Headers to the proxied request. For example, use Apache's mod_proxy to map a local path to the pixel URL, then add cache rules for that path. Note that this requires server admin access and basic config knowledge.

内容的提问来源于stack exchange,提问作者Daud Khan

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.06 16:17:41