JMeter – URL Patterns to Exclude

This is a common question why use the ‘URL Patterns to Exclude’ option while recording the JMeter script?

In today’s world, a web application has multiple components which are loaded on the screen. Most of the components are static and saved in the browser cache to reduce the network traffic and boost the loading speed of the page. Hence these static components do not involve in direct communication with the server while browsing the successive pages of the application.

What are the static components/elements on a web page?

  • Image (.png, .jpg, .jpeg etc.)
  • Cascading Style Sheet (.css)
  • JavaScript (.js)
  • Interchange Format (.gif, .jif etc.)
  • favicon.ico
  • Adobe Flash File (.swf)
  • Font Format (.woff, woff2 etc.)

While recording the web application through the JMeter proxy server, these static components get recorded for every page. Since JMeter does not have any browser so static components do not get cached and requested for each page. The server also responds to all such requests which make an extra burden on it.

To restrict the static components request and simulate the real-world scenario, JMeter has the option to filter out the static request URL during the test script recording. This option is available in the ‘Requests Filtering’ tab of ‘HTTP(S) Test Script Recorder’ where you can get the section ‘URL Patterns to Exclude’.

JMeter - URL Patterns to Exclude
Figure 01: HTTP(S) Test Script Recorder

If you know what the static elements are present in the web application then list them out using a regular expression. For example, you want to exclude all the requests which are ended with .png then write an expression .*\.png by adding a row under this section. In case you are not aware of the static element then you can click on the ‘Add Suggested Excludes’ button. JMeter will automatically add a row with the most common static element URL pattern.

Why sometimes ‘URL Patterns to Exclude’ does not work?

It does not work when excluded URL has some additional parameters which are appended at the end of the URL.

Example:

You excluded the pattern .jpg and the web application has a URL www.testdemosite.com/image.jpg?name=sitelogo then JMeter will capture this request.

Reason:

The reason is a regular expression (?i).*.(bmp|css|js|gif|ico|jpe?g|png|swf|woff|woff2) does not satisfy the condition to capture the URL having appended parameters.

Solution:

Add .* at the end of the regular expression like (?i).*.(bmp|css|js|gif|ico|jpe?g|png|swf|woff|woff2).*

Explanation:

.* is used for ‘Any Character’ which instructs to JMeter that after the given keywords possibly there could be some more characters.

How to add a new URL pattern to exclude from the recording?

You can add the new URL pattern or keyword in the given group and separate it out by | (pipe sign).

(?i).*.(bmp|css|js|gif|ico|jpe?g|png|swf|woff|woff2|abc|def)


You may be interested: