1

Question

How do I reduce the time between clicking an extension icon and the content being displayed?

Support

I'm making a very simple extension. It loads quickly once it's started, but there is a bit of a delay between clicking and the popup loading. I've added a gif of this here. (The gif gets a bit hectic to look at, so I've put it under a link so that it doesn't burn your eyes!) It doesn't really do it justice as it loads faster on my machine than other people's for some reason.

This question (Slight loading delay with chrome extension popup) seems to address the same question, but it doesn't have an answer. I think that this question (load chrome extension popup faster) addresses this issue too, but its answer seems to be addressing a different problem.

My repo is here: https://github.com/bvn-architecture/shackleton

If I profile the load time of the extension it starts measuring from when the popup appears:

enter image description here

This implies that there is something on the screen about 5ms after loading. It doesn't include the pause.

Community
  • 1
  • 1
Ben
  • 12,614
  • 4
  • 37
  • 69
  • Try putting jQuery as a script file in your extension instead of loading it externally. – Rob W Mar 22 '15 at 09:53

1 Answers1

2

I think the delay you are facing is due to the time necessary to launch a new task process in Chrome.

Open Chrome menu > More tools > Tasks manager, you will not see any reference to your extension.
Now click on your extension browser-action icon, you will see that, after some various delay, a new entry called "Extension : BVN toolbar" will appear in the tasks manager. Once the task appears, your popup opens.

Some tests

If you test the My Bookmarks sample extension from the Chrome extension samples, you will see the exact same behavior.

Now if you have a look at some other extensions like Adblock Plus for example, which uses a browser-action icon/popup like you, you will see that its popup opens much faster than yours.
If you check the tasks manager again you will see a task named "Extension : Adblock Plus" even when the popup is not opened.

Explanations

This is because many extensions (like the Adblock one) are using persistent background pages which are single long-running scripts existing for the lifetime of your extension (until you disable it, close your browser etc.)

As mentioned in the documentation, the use of persistent background pages is discouraged in favor of event pages (non persistent ones). But in your case, using an event page will not solve your problem because when the event page is not actively doing something, it is unloaded to release resources.

Solutions

The easy way

Defining a persistent background page in your manifest.json file will solve your problem but will result in a not really necessary memory usage to keep your extension task "alive" (and your extension don't need it to work):

"background": {
    "page": "popup.html"
},

The other way

Submit the question / problem to Google. Maybe they can perform some optimizations for such case or they will provide you a better solution. And you can explain that this encourages the use of persistent background page instead of event ones :-)

rd3n
  • 4,440
  • 1
  • 33
  • 45