从Wordpress站点上的静态资源中删除查询字符串

时间:2016-09-28 16:12:26

标签: php wordpress .htaccess caching

我在从Wordpress网站上的静态资源中删除查询字符串时遇到了困难。我已经尝试了常见的function.php代码,它似乎适用于大多数但我的Pingdom分析并没有改变。

如果这会影响到某些事情,我会安装WordFence和Cache Enabler。

以下是我使用的代码:

function _remove_script_version( $src ){
    $parts = explode( '?ver', $src );
        return $parts[0];
}
add_filter( 'script_loader_src', '_remove_script_version', 15, 1 ); 
add_filter( 'style_loader_src', '_remove_script_version', 15, 1 ); 

remove_action( 'wp_head', 'print_emoji_detection_script', 7 ); 
remove_action( 'wp_print_styles', 'print_emoji_styles' ); 

我的.htaccess中也有这个来帮助缓存:

<IfModule mod_expires.c>
# Enable expirations
ExpiresActive On 

# Default directive
ExpiresDefault "access plus 1 month"

# favicon
ExpiresByType image/x-icon "access plus 1 year”

# images
ExpiresByType image/gif "access plus 1 month"
ExpiresByType image/png "access plus 1 month"
ExpiresByType image/jpg "access plus 1 month"
ExpiresByType image/jpeg "access plus 1 month"

# css
ExpiresByType text/css "access plus 1 week”

# javascript
ExpiresByType application/javascript "access plus 1 week"
</IfModule>

<ifModule mod_headers.c>
  <filesMatch ".(css|jpg|jpeg|png|gif|swf|svg|js|ico)$">
    Header set Cache-Control "max-age=2592000, public"
  </filesMatch>
  <filesMatch ".(x?html?|php)$">
    Header set Cache-Control "private, must-revalidate"
  </filesMatch>
</ifModule>

<IfModule mod_deflate.c>
  # Compress HTML, CSS, JavaScript, Text, XML and fonts
  AddOutputFilterByType DEFLATE application/javascript
  AddOutputFilterByType DEFLATE application/json
  AddOutputFilterByType DEFLATE application/atom+xml
  AddOutputFilterByType DEFLATE application/rdf+xml
  AddOutputFilterByType DEFLATE application/rss+xml
  AddOutputFilterByType DEFLATE application/vnd.ms-fontobject
  AddOutputFilterByType DEFLATE application/x-font
  AddOutputFilterByType DEFLATE application/x-font-opentype
  AddOutputFilterByType DEFLATE application/x-font-otf
  AddOutputFilterByType DEFLATE application/x-font-truetype
  AddOutputFilterByType DEFLATE application/x-font-ttf
  AddOutputFilterByType DEFLATE application/x-font-woff
  AddOutputFilterByType DEFLATE application/x-javascript
  AddOutputFilterByType DEFLATE application/xhtml+xml
  AddOutputFilterByType DEFLATE application/xml
  AddOutputFilterByType DEFLATE font/opentype
  AddOutputFilterByType DEFLATE font/otf
  AddOutputFilterByType DEFLATE font/truetype
  AddOutputFilterByType DEFLATE font/ttf
  AddOutputFilterByType DEFLATE image/svg+xml
  AddOutputFilterByType DEFLATE image/x-icon
  AddOutputFilterByType DEFLATE text/css
  AddOutputFilterByType DEFLATE text/html
  AddOutputFilterByType DEFLATE text/javascript
  AddOutputFilterByType DEFLATE text/plain
  AddOutputFilterByType DEFLATE text/xml
</IfModule>

1 个答案:

答案 0 :(得分:0)

你的PHP工作正常。我只是在登台服务器上运行它,它完全剥离了版本和表情符号脚本。

除此之外,几乎可以肯定是缓存问题。

你的.htaccess不应该与它有任何关系,因为问题是由WordPress提出的,而不是静态资产本身需要更新。

我会进入Cache Enabler的设置页面并点击&#34; Save&#34;按钮。根据他们的文档,这应该清除所有当前的缓存并清理你的问题。

https://www.keycdn.com/support/wordpress-cache-enabler-plugin/

  • 干杯!