Possibilities to cache Chrome extension scripts and assets

142 views
Skip to first unread message

Alexander

unread,
Aug 6, 2020, 9:09:10 AM8/6/20
to Chromium Extensions
Hello, I would like to cache chrome extension files (eg. Fonts, scripts, icons),
but the http response:
url: chrome-extension: //<extension-id>/image.png
Cache-Control: no-cache

Neither through the manifest, nor even through the webRequest.onBeforeSendHeaders it is possible to enable the file cache.. serviceworker cache not working with chrome-extension scheme too

if there are any options at all to do this?
 if not, is it possible to add such capability for chrome extensions in the future?

wOxxOm

unread,
Aug 6, 2020, 10:16:28 AM8/6/20
to Chromium Extensions, Alexander
Caching is not needed for chrome-extension:// resources as they are local files and hence are as fast as any cached files. Well, usually, at least. There could be some improvement in case the browser profile is on a network drives. Also, admittedly, the *in-memory* caching is faster. However, there should be no difference in any realistic usage scenario because decoding/parsing phase takes much longer usually.

If you can demonstrate the need for caching by providing a demo extension, it might be reconsidered. Personally, though I doubt it because usually bottlenecks in such cases are caused by something else.

Alexander

unread,
Jan 13, 2021, 6:05:34 PMJan 13
to Chromium Extensions, wOxxOm, Alexander

As example on this two screenshots:
first: 280ms to load image from local chrome-extension://
and at second screenshot 0ms to load image from memory cache

right now i can't contain wallpapers locally because loading is slow and only way to cache is upload local recource through https proxy, but it's awful at all..
четверг, 6 августа 2020 г. в 17:16:28 UTC+3, wOxxOm:
1.png
2.png

Alexander

unread,
Jan 14, 2021, 3:56:43 AMJan 14
to Chromium Extensions, Alexander, wOxxOm
I can send you build where you could check local resources vs memory cache, the difference significant
четверг, 14 января 2021 г. в 01:05:34 UTC+2, Alexander:

Jackie Han

unread,
Jan 14, 2021, 4:30:10 AMJan 14
to Alexander, Chromium Extensions, wOxxOm
Could show waterfall details?
"Time" column is not accurate, because it includes "Stalled" time especially when you have many resources to load.
But memory cache just tells you "0ms".
Local files are not as fast as memory caching, but it is still very fast. See my screenshot below.
Screen Shot 2021-01-14 at 5.20.32 PM.png


--
You received this message because you are subscribed to the Google Groups "Chromium Extensions" group.
To unsubscribe from this group and stop receiving emails from it, send an email to chromium-extens...@chromium.org.
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/chromium-extensions/b794672d-3059-45b5-8552-5122d2a51a9dn%40chromium.org.


--
韩国恺(Jackie)

wOxxOm

unread,
Jan 14, 2021, 5:18:19 AMJan 14
to Chromium Extensions, Jackie Han, Chromium Extensions, wOxxOm, Alexander
Also note that to analyze performance properly the entire page load process should be measured in devtools profiler or chrome://tracing. Not just the resources. It's also quite possible there's a bug or an inherent slowness in filesystem protocol handling. Anyway, it's best to report on https://crbug.com with a demo extension attached.

Homey

unread,
Jan 14, 2021, 6:03:00 AMJan 14
to Chromium Extensions, Jackie Han, Chromium Extensions, wOxxOm, Alexander
Jackie Han, 
Sure! here are the  waterfall details and video with user tests comparison 
четверг, 14 января 2021 г. в 11:30:10 UTC+2, Jackie Han:
local_file.png
test_local.mov
test_memory-chache.mov
memory_cache.png

Jackie Han

unread,
Jan 14, 2021, 7:28:51 AMJan 14
to Homey, Chromium Extensions, wOxxOm, Alexander
Hi Homey,

From the information you provided, I think of a similar situation I encountered in the past. So, let me say my guess based on my experience.
1. If your image is very large (large file size and/or large resolution, e.g. 5000x3000), Chrome will have a noticeable delay to display the image.
2. When you upload images to a CDN provider, by default, CDN providers will compress the picture enormously(hugely) to speed up network transmission. After that compression, the picture has become very small and the resolution has been reduced. Thus Chrome will display it quickly.

Could you compress your background image to a smaller size, and test it again?
Another suggestion,  remove all other resources, just only test image load speed, like this:

<html>
<body>
  <img src="image.jpg"> <!-- test jpg format -->
  <!-- Or test webp format <img src="image.webp"> -->
</body>
</html>

Best
--
韩国恺(Jackie)

Jackie Han

unread,
Jan 14, 2021, 7:34:33 AMJan 14
to Homey, Chromium Extensions, wOxxOm, Alexander
Also, if you use URL.createObjectURL(blob) for a large image as the image.src attribute, it also has noticeable delay.
--
韩国恺(Jackie)
Message has been deleted

Homey

unread,
Jan 14, 2021, 7:52:37 AMJan 14
to Chromium Extensions, Jackie Han, Chromium Extensions, wOxxOm, Alexander, Homey
I uploaded it without any compression as file on my web server: https://api.homey-app.online/wallpapers/lighthouse.jpeg (3375x2250)
and use just file url "filesystem:chrome-extension://..."


---
Alexander

Homey

unread,
Jan 14, 2021, 8:19:31 AMJan 14
to Chromium Extensions, Homey, Jackie Han, Chromium Extensions, wOxxOm, Alexander
right now it's impossible optimize loading speed of local files, only by upload them to https
but with scripts it's impossible regards policy and security issues 

четверг, 14 января 2021 г. в 14:52:37 UTC+2, Homey:

Jackie Han

unread,
Jan 14, 2021, 8:30:21 AMJan 14
to Homey, Chromium Extensions, wOxxOm, Alexander
Screen Shot 2021-01-14 at 8.58.17 PM.pngScreen Shot 2021-01-14 at 8.59.36 PM.png
In my test, reducing the file size can reduce loading time a bit.
I don't know "filesystem:chrome-extension://..." , I use "chrome-extension://..." .

--
韩国恺(Jackie)

Jackie Han

unread,
Jan 14, 2021, 8:38:35 AMJan 14
to Homey, Chromium Extensions, wOxxOm, Alexander
I test localhost://image.jpeg vs chrome-extension://extension_id/image.jpeg
It seems there is no difference in speed.

On Thu, Jan 14, 2021 at 9:19 PM Homey <silves...@gmail.com> wrote:


--
韩国恺(Jackie)

Homey

unread,
Jan 14, 2021, 8:41:21 AMJan 14
to Chromium Extensions, Jackie Han, Chromium Extensions, wOxxOm, Alexander, Homey
ok, no matter filesystem: or just chrome-extension:// , the same problem, crop size can give some optimization, but unfortunately not solving a problem,
possibility to add crome-extension:// to memory-cache via service worker could solve this problem, 
may be chrome will implement it some time.. or i just dont know ways to optimize it 
четверг, 14 января 2021 г. в 15:30:21 UTC+2, Jackie Han:

guest271314

unread,
Jan 14, 2021, 9:08:32 AMJan 14
to Chromium Extensions, silves...@gmail.com, Jackie Han, Chromium Extensions, wOxxOm, Alexander
Since the file is local you can utilize File System Access API (Native File System) to get the local image without using networking at all.

Homey

unread,
Jan 14, 2021, 9:16:55 AMJan 14
to Chromium Extensions, guest...@gmail.com, Homey, Jackie Han, Chromium Extensions, wOxxOm, Alexander
yes, this issue about: local access working much slower than using networking with cache 

четверг, 14 января 2021 г. в 16:08:32 UTC+2, guest...@gmail.com:

guest271314

unread,
Jan 14, 2021, 9:52:15 AMJan 14
to Chromium Extensions, silves...@gmail.com, guest271314, Jackie Han, Chromium Extensions, wOxxOm, Alexander
Why is networking necessary at all? Since the file is local you can get th image without networking

const [fileHandle] = await self.showOpenFilePicker();
const file = await fileHandle.getFile();


guest271314

unread,
Jan 14, 2021, 9:55:40 AMJan 14
to Chromium Extensions, guest271314, silves...@gmail.com, Jackie Han, Chromium Extensions, wOxxOm, Alexander
If networking is required to get the file you can use <link rel="prefetch">

guest271314

unread,
Jan 14, 2021, 10:04:35 AMJan 14
to Chromium Extensions, guest271314, silves...@gmail.com, Jackie Han, Chromium Extensions, wOxxOm, Alexander

Homey

unread,
Jan 15, 2021, 5:36:53 PMJan 15
to Chromium Extensions, guest...@gmail.com, Homey, Jackie Han, Chromium Extensions, wOxxOm, Alexander
Wow! <ink rel="preload"> significantly increased performance. It's exactly what looking for, thank you!

четверг, 14 января 2021 г. в 17:04:35 UTC+2, guest...@gmail.com:
Reply all
Reply to author
Forward
0 new messages