Skip to content
This repository was archived by the owner on Apr 2, 2020. It is now read-only.

Conversation

@moving-bits
Copy link

added timeout function

If a requested script cannot be loaded successfully within timeout span, fallback automatically tries to load from the next fallback url (without interrupting the original download). First successful download for each library wins.

Use case for this is a slow responding network, in my case a proxy server which took 60s to return the error code, thus taking my page (with a couple of included scripts and fallback scripts) more than four minutes to load! Now with timeout function it is down to less than 20 seconds.

Currently timeout is set to five seconds. For v2 of fallback this parameter could be made configurable.

@sgarbesi
Copy link
Member

me.add_sri_attributes won't always be executed when the page loads. It's possible that this can run based on a User action such as a Click much later after the page has finished loading, in which you a developer may want to lazy load a library. The now variable would need to be defined there in the local scope.

@moving-bits
Copy link
Author

me.add_sri_attributes won't always be executed when the page loads. [...]

Hm, not sure if I understand you... I defined now in method fallback.spawn.instance (not me.add_sri_attributes) which (to my understanding) is the method where loading a library starts, whether this happens during loading the page or at a later time.
I use this now value only to calculate the timeout value which I save a couple of lines further down (in the same method) in variable me.timeouts[library] which I inspect each time my timer gets called.
Should be fine - or have I missed something?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants