How to set disable cache option in k6?

Hi. Interested in setting up “disable cache” option in k6/browser, as well as “network throtling params”. Couldnt find such in official docs.


Thanx in advance

i’ve found chromedevtools protocol definitions.



there are network conditions and setdisablecache options are exist, but i’m not sure if K6 can use it via CDP, can you help please?

Hi @psixoz1,

Welcome to the forum!

We are currently working on network throttling and hope to have it in the next release (v0.48.0). You can find the details of this work in this issue.

I’d like to get a better understanding of what your use case is to disable the cache. How will this help you?

Cheers,
Ankur

1 Like

@ankur if its not problem for you, could you please share a js code example for my particular case in browser testing:
Where test should be finished when awaited API request receives status code = 200


where current code is not containing this part of code

export default async function () {
const page = browser.newPage()
try {
await page.goto(base_url)
} finally {
page.close()
}
}

In k6, you can disable caching by setting the noConnectionReuse option to true . This option prevents k6 from reusing TCP connections, effectively disabling caching. Here’s an example of how you can use it:

import http from ‘k6/http’;

export default function () {
// Your test script here

// Disable cache by setting noConnectionReuse to true
http.get(‘https://example.com’, { noConnectionReuse: true });
}

Note that this approach might impact the performance of your tests, as it prevents connection reuse. Use it carefully, and only disable caching when it’s necessary for your specific testing requirements.

1 Like

I suppose it’s not a correct answer:
The point is k6 running browser with commands and need to get throught with some prefs to browser (chromium) in order that option would be enabled\disabled.
the option you mentioned is only K6 option, but not a browser one.

K6 might not use any cache, but browser will anyway. Untill you pass a correct option when run a test, like playwright does with its setcacheDisabled to true

1 Like

Hi @psixoz1,

if its not problem for you, could you please share a js code example for my particular case in browser testing:
Where test should be finished when awaited API request receives status code = 200

export default async function () {
const page = browser.newPage()
try {
await page.goto(base_url)
} finally {
page.close()
}
}

So you want to wait until the widget.css request has completed with 200? Why is that? I’m trying to understand your use case so that I can see what solutions we can come up with.

Untill you pass a correct option when run a test, like playwright does with its setcacheDisabled to true

My guess is that when caching is enabled, the dependent files (such as widget.css) will be cached by chrome, and so after the first iteration the test will not try to retrieve the dependent files again since they’re cached. This is why you want to disable the cache, correct?

Currently the way that the browser module is implemented, each iteration will start and stop a new instance of Chrome with it’s own cache. When the Chrome instance is shutdown the browser module deletes the cached data. So each iteration is sandboxed from each other, and so effectively this means that caching is disabled. Although, when you work with your own remote Chrome instances with the K6_BROWSER_WS_URL env var, the cached data will not be deleted by the browser module.

Why is it important for your test to always need to wait on the dependent files? Could you work with the k6 http.get API instead when you want to check how specific requests have performed?

Take a look at this comment, which might be able to help since you’re interested in all/specific requests your website makes when it is navigated to.

Cheers,
Ankur

So you want to wait until the widget.css request has completed with 200? → positive
Why is that? → this element loads the latest on the page after all other requests been completed. check the pic

If i switch to 3g the page i load in 30 secs loads almost a minute. any other dom objects are loaded and rendered, meanwhile STATIC content like pictures still downloads.
Thats why those web vitals is not actual at this point. WV are good only for quick loaded sites and are not usable if we have or test slow connections. I need some last action closely to finish downloading WHOLE page. Iteration duration in summary will be the finish loading time in this case.

I found some usable method on playwright it calls waitforresponse this is what i need, but its not applied yet on playwright plugin for k6, and possibly never will.

http.get is not fit for my purposes as it just sends request and receives response. i need to catch proper response, at the time it should be awaited in the site loading waterfall

Hi @psixoz1,

Thanks for the details. We need to consider the feature request a bit more and might have an update soon for you on possible short term solutions.

In the meantime have you tried working with networkidle when calling goto, such as await page.goto('https://example.com', { waitUntil: 'networkidle' });. Using networkidle will wait until all the network requests have completed (including the static files at the end).

Cheers,
Ankur

Networkidle is not working properly as i think. it always exits by timeout, even if i set 5 minutes. But for sure site content loads before this.
networkidle hardly even can be used, as many sites collects analytics like sentry pings and etc. network is not fully idle i think

Hi @psixoz1,

Networkidle is not working properly as i think. it always exits by timeout, even if i set 5 minutes. But for sure site content loads before this.
networkidle hardly even can be used, as many sites collects analytics like sentry pings and etc. network is not fully idle i think

That makes sense, it was a long shot in terms of a work around. Another possible work around could be asserting that an element exists before carrying on with the test. Is there an element that could be waited on after widget.css has loaded?

One more question is, why do you need to wait on widget.css before carrying on with the test? Is the test exiting before widget.css is downloaded?

Cheers,
Ankur