What is a query string?
![图片[1]-如何从 WordPress 中的静态资源中删除查询字符串-光子波动网 | 专业WordPress修复服务,全球范围,快速响应](https://www.361sale.com/wp-content/uploads/2024/04/image-617.png)
A query string is the set of characters that follow the question mark in a URL. These strings act asURL Parameters, helps to sort and specify content on the site.
An example of a link containing a query string is shown below:
https://example.com/products?category=shoes&sort=price_asc
In this example:
category=shoes
is a parameter that tells the server to display only footwear products.sort=price_asc
is another parameter that instructs the server to sort the results in ascending order of price.
Why do I need to delete the query string?
For static resources that change infrequently, such as CSS, JavaScript, or images, using query strings may not be as useful. In fact, query strings may prevent these resources from being efficiently cached on the user's browser or network. This slows down the loading speed of the website.
In some website performance testing tools, such as GTMetrix maybe Pingdom, you may see query strings that suggest removing these static resources. Doing so will help these files to be cached, improving the loading speed and overall performance of your website.
Removing query strings from static resources in WordPress
If you want to improve the loading speed of your WordPress site, removing query strings from static resources such as CSS and JavaScript files is an effective strategy. There are two main ways to accomplish this:
- Edit the functions.php file: This method requires you to add a new function directly to your WordPress theme's
functions.php
Add some code to the file. This approach requires some programming knowledge but allows you to directly control and optimize your website. - Using WordPress Performance Plugins: If you are not familiar with coding, you can choose to install a performance optimization plugin. These plugins usually provide user-friendly interfaces to help you remove query strings easily and quickly.
![图片[2]-如何从 WordPress 中的静态资源中删除查询字符串-光子波动网 | 专业WordPress修复服务,全球范围,快速响应](https://www.361sale.com/wp-content/uploads/2024/04/image-513.png)
Remove query strings from static resources using code
In the edit functions.phpIt is recommended that you create a backup of your website before you code in the
To access the file via the WordPress dashboard, navigate to theAppearance -> Theme File Editor.Find the right sidebar on thefunctions.php file.
![图片[3]-如何从 WordPress 中的静态资源中删除查询字符串-光子波动网 | 专业WordPress修复服务,全球范围,快速响应](https://www.361sale.com/wp-content/uploads/2024/04/image-502.png)
Copy and paste the following code snippet:
// Remove query string from static resources
function remove_cssjs_ver( $src )
{
if( strpos( $src, '?ver=' ) )
$src = remove_query_arg( 'ver', $src ); return $src
return $src.
}
add_filter( 'style_loader_src', 'remove_cssjs_ver', 10, 2 );
add_filter( 'script_loader_src', 'remove_cssjs_ver', 10, 2 ); }
After completing the code edits, theSave changes.
Removing query strings from static sources using plugins
mountingSpeed Booster PackPlugin. It is an all-in-one WordPress plugin that helps you improve the loading speed of your website. One of its features includes removing query strings from static resources.
- On the WordPress admin page, navigate to thePlugins -> Add New Plugin. Look in the search box forSpeed Booster Pack.after thatInstallationfurthermoreactivateThe
![图片[4]-如何从 WordPress 中的静态资源中删除查询字符串-光子波动网 | 专业WordPress修复服务,全球范围,快速响应](https://www.361sale.com/wp-content/uploads/2024/04/image-505.png)
- Refresh the page and navigate toSpeed Boostermenu and selectGeneralClick on the Click on the"Trimming query strings" option next to theON switchto activate it, and when you're done, click"Save." . Removes the query string from all static assets.
![图片[5]-如何从 WordPress 中的静态资源中删除查询字符串-光子波动网 | 专业WordPress修复服务,全球范围,快速响应](https://www.361sale.com/wp-content/uploads/2024/04/image-506.png)
Best plugin for removing query strings from static resources
In addition to the plugins mentioned above, three alternatives are offered. These plugins can also perform multiple tasks to help increase the speed of your website.
![图片[6]-如何从 WordPress 中的静态资源中删除查询字符串-光子波动网 | 专业WordPress修复服务,全球范围,快速响应](https://www.361sale.com/wp-content/uploads/2024/04/image-507.png)
To remove query strings from static resources using WP Rocket, go to the"Basic Settings"option, and then click"File optimization". Then, go ahead and check theRemoving query strings from static resourcesFrame.
![图片[7]-如何从 WordPress 中的静态资源中删除查询字符串-光子波动网 | 专业WordPress修复服务,全球范围,快速响应](https://www.361sale.com/wp-content/uploads/2024/04/image-508.png)
W3 Total Cache also has a feature that helps you remove query strings from static resources. After installing the plugin, go to"Performance" -> "Browser Cache"and enable "Remove query strings from static resources"Options.
To prevent your WordPress site from creating query strings again, go to thebrowser cacheand check theSetting up cache prevention objects after a changeOptions.
3,WP Performance Score Booster
![图片[8]-如何从 WordPress 中的静态资源中删除查询字符串-光子波动网 | 专业WordPress修复服务,全球范围,快速响应](https://www.361sale.com/wp-content/uploads/2024/04/image-509.png)
WP Performance Score Booster is a free plugin for browser caching, GZIP compression and removing query strings from static resources toSettings -> WP Performance Score Booster.Then, click "Remove query string from static content"and save the changes.
Test final results
The query string has been removed from every static resource on your website and it's time to check the performance of your website. You can use any website performance tool such as GTMetrix, Pingdom or PageSpeed.
For example, let's use GTMetrix to display test results before and after optimization. First fill in your website address in the field provided, then click theTest your websiteThe
![图片[9]-如何从 WordPress 中的静态资源中删除查询字符串-光子波动网 | 专业WordPress修复服务,全球范围,快速响应](https://www.361sale.com/wp-content/uploads/2024/04/image-510.png)
reach a verdict
The query string is part of the URL of the website that contains the " ?"Characters such as. " and " &." . A way to remove query strings from static resources in WordPress:
- Edit the functions.php file--Find your way through the WordPress dashboard!functions.phpDocumentation. Insert the supplied code into thefunctions.phpfile and save the changes.
- Installation of plug-ins- Install and activate Speed Booster Pack. in the WordPress dashboard, go toSpeed Booster -> GeneralTheThen, activate theTrimming the query stringOptions. We have also listed other caching plugins that you can use as alternatives.
Link to this article:https://www.361sale.com/en/7821The article is copyrighted and must be reproduced with attribution.
No comments