-
Notifications
You must be signed in to change notification settings - Fork 12
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add timeout for network requests #18
Comments
This issue needs more discussion! |
That's a must have feature, indeed. Any other thoughts? |
👍 Also, responding with a cached version seems very appealing, but it also has a huge problem with _predictability_. Let's examine a use case. Let's say the timeout is defined as 8s and everything is set to respond with a cached version if the network times out. It may just happen that an updated CSS file is downloaded at 7.8s but a JS file times out and the user gets an outdated version of it. The application will be in an inconsistent state and likely broken. For an application-wide "show cached version if connection is slow" use case, I guess the ideal solution would be to apply the timeout only to the first request in the page (e.g. the HTML file), if it is too slow then flip the switch and serve all resources from cache. This would ensure the application is always in a consistent state, the user gets either the latest version or the old version—not a bit of each—thus ensuring predictable behavior. I'm just throwing some ideas out here, hopefully it's some food for thought. I've just spent a few minutes thinking about this issue and came up with so many options, that's one of the reasons I usually dislike declarative abstractions—they are never flexible enough, and when they try to be they end up becoming so goddamn bloated with feature creep that it is often easier to write the imperative code for it than trying to figure out all of the declarative abstraction's options and values. So, please, give some thought about what is really worth implementing before trying to cover every single use case. Balance is very important here. 😄 |
Nice. I actually believe we have an easy way to allow developers to decide what is the best solution as well as keeping the configuration object quite simple. Only two actions required (and one already exists):
"timed-out-images": {
"match": {
"extension": ["png", "jpg", "jpeg", "gif"], // could be any match
"status": 408 // that has a 408 status
},
"apply": {
"fetch": "another-source.jpg" // to something else
}
}, But as @UltCombo mentioned, there are cases in witch we may prefer to have it from cache, so:
"images": {
"match": {
"extension": ["png", "jpg", "jpeg", "gif"] // again, any match
},
// it only makes sense if it is online-first or if it is the first time with "fastest" strategy
"strategy": "online-first",
// the new feature
"timeLimit": {
timeout: 2000,
// default is true, if false, it becomes a 408 (which may fall into
// another rule) like the previous one
useCache: false
},
"apply": {
// cache could still be used in case of 404
"cache": {
"name": "cached-images",
"version": "1"
}
}
} In case timeout is defined, useCache is false and there is cache in apply (the example above):
In case timeout is defined, useCache is true but there is no cache in apply:
If timeout is defined and there are no rules to treat 408 requests, it ends up like a failed 408 request, indeed. I believe it covers all possible situations, by adding one simple configuration object to it. By the way, DSW already works with a |
Nice! Very throughout explanation. 😄 I'm just not sure what's the use case for responding with a cached version when the resource is not found (404). If the request reaches the server and the server responds with 404, the resource likely doesn't exist anymore—for what use cases would it make sense to use a cached version of something that no longer exists? |
Well, it may still exists but your device may have lost its connection. |
Well, I thought you were talking about a 404 response—if you get a 404 back then it means the connection to the server is working and the resource doesn't exist anymore. I believe connection errors would fail the fetch request instead of returning a 404 response. |
Nope...fetch will not fail, instead, it will resolve with the fetch('/non-existing-page').then(function(response){
console.log(response); // Response { status: 404, statusText: "Not Found" }
}); |
I guess we may be having some communication problem. Let's try again.
Here you are talking about connection problems (e.g. device is offline), right? That's what I'm trying to address. However, it seems you are mixing it up with 404, which is just a server response—that means fetch request reached the server successfully and the server responded with a "not found" status. |
To be more clear, your comment above mentions handling 404s with cached responses, but then you said the cache would be used to allow the page to work offline. This doesn't seem to add up for me as those are two very different cases as far as I can see. |
hm, I understand. But I see only two possible outputs. The cashed version, or the failure itself. |
Yes, exactly.
I believe this may happen under a few circumstances:
So yeah, I believe there are cases when the user may want to handle 404s in different ways, but we may be starting to get a bit off-topic. It seems DSW already has a way to set the handling for specific HTTP status codes, right? I believe that can be used to determine how 404s will be handled. I'm just not sure how the |
Good points, @UltCombo , indeed. Yes, it's possible to define different rules for different 404 cases and it is, a little bit off topic to Anyway, are we in the same page about the |
I guess you mean "default fail behavior", right? I'm not sure if 404 qualifies as a failed request, but as long as the user can customize the handling for such cases it doesn't really matter.
I'm just not sure how |
We should definitely have a way to define for how long the user will stay waiting for a request before we kill it and deliver something else (like a custom page or default value).
The text was updated successfully, but these errors were encountered: