cyrus-and / chrome-har-capturer

Capture HAR files from a Chrome instance
MIT License
535 stars 90 forks source link

Cache 304 Not Modified possible with second load? #62

Closed petericebear closed 6 years ago

petericebear commented 6 years ago

Hi,

i am trying to leverage browser cache foe a second load off the page. Is that possible?

I tried: xargs chrome-har-capturer -k -o output.har < urls.txt

When I view the HAR file, I don't see 304 Not Modified in the results. But when I load in the browser and look in the "Network" tab, then it works good.

Any idea's?

NB: urls.txt only conatins the same url twice.

petericebear commented 6 years ago

Looks like, you made it already after the last release. Can you tag a new release for the cache? :D

cyrus-and commented 6 years ago

How come that you didn't receive the unknown option `-k' error then?

petericebear commented 6 years ago

I do not know. I just installed it and tried several options out

cyrus-and commented 6 years ago

I mean it might not be that problem then, are you sure that with the version from master you get 304s as expected?

petericebear commented 6 years ago

I just copied the changes to the files on my drive from that commit. Unfortunatly still only status 200 status codes from the images.

petericebear commented 6 years ago

Hmm, wait a bit: https://www.texel.net/nl/accommodaties/vakantiehuisje

I see also a status 200 in the browser itself but it shows: 200 (from memory cache) in the network tab.

cyrus-and commented 6 years ago

Look at this:

$ node bin/cli.js -k https://cardaci.xyz https://cardaci.xyz | grep _fromDiskCache
- https://cardaci.xyz/ ✓
- https://cardaci.xyz/ ✓
                "_fromDiskCache": false,
                "_fromDiskCache": false,
                "_fromDiskCache": false,
                "_fromDiskCache": false,
                "_fromDiskCache": false,
                "_fromDiskCache": false,
                "_fromDiskCache": true,
                "_fromDiskCache": true,
                "_fromDiskCache": true,
                "_fromDiskCache": true,
                "_fromDiskCache": true,
                "_fromDiskCache": true,
petericebear commented 6 years ago

mbp-peter:chrome-har-capturer peter$ node bin/cli.js -k https://cardaci.xyz https://cardaci.xyz | grep _fromDiskCache

No _fromDiskCache

petericebear commented 6 years ago

I am trying this on my OSX, latest node version: v8.11.2, chrome version 67.0.3396.62 (Officiële build) (64-bits)

cyrus-and commented 6 years ago

_fromDiskCache disk cache must be present (either true or false), are you sure that you're using the latest version? Try a git pull.

petericebear commented 6 years ago

Ah yes was an old version. Now it works. Is it possible to remove the cache after firing the script twice? I mean clean the cache in the Chrome?

If I now run the script 2 times after it, then the first request is also with the cache

cyrus-and commented 6 years ago

Great! Bumping the new version...

If you need "advanced" features you can always use this as a library and perform the desired initialization yourself using chrome-remote-interface which is a dependency anyway.

Otherwise just run:

$ chrome-remote-interface inspect <<<'Network.clearBrowserCache()'
cyrus-and commented 6 years ago

Bumping the new version...

v0.13.0