davidyack / Xrm.Tools.CRMWebAPI

This is an API helper for working with the Common Data Service (CDS) Web API
MIT License
143 stars 73 forks source link

Status of cached files is excluded #24

Open ghost opened 7 years ago

ghost commented 7 years ago

Status 304 is excluded for XMLHttpRequests. This will give an error when retrieving a cached file.

davidyack commented 7 years ago

Currently we aren't supporting the If-Match yet on a Get to support checking for a change - I assume that is what you are after? Can we change the title of this to "Support conditional retrievals" I would like to see this added in a future update

ghost commented 7 years ago

I'm refering to this. you check in boundries of 200-299 but 304 for cached data would be ok as well.

req.onreadystatechange = function () {
            if (this.readyState == 4 /* complete */ ) {
                req.onreadystatechange = null;
                if ((this.status >= 200) && (this.status < 300)) {
                    callback(false, {
                        'response': this.response,
                        'headers': self.parseResponseHeaders(this.getAllResponseHeaders())
                    });
                } else {
                    callback(true, this)
                }
            }
        };
davidyack commented 7 years ago

Yes, right now I don't believe there a way we can encounter a 304 until we expose a way to do conditional retrievals - So agree when we add logic to support that we will need to expand to support 304 being returned

re - http://docs.oasis-open.org/odata/odata/v4.0/os/part1-protocol/odata-v4.0-os-part1-protocol.html#_Toc372793647

ghost commented 7 years ago

But what if cache control is added in the response header? like Cache-Control:public, then the browser could cache.

davidyack commented 7 years ago

That is a good question I've not seen anything one way or the other - have you seen something that would indicate that would also return a 304, seems like that would conflict with the ability to do the conditional retrieval check if it interfered no?

ghost commented 7 years ago

If you have the devtools open and watch the status of for example webresources they will turn to 304 if you reload sometimes. But don't forget to uncheck "disable cache if devtools are open" IE and chrome behave differently of course. Some elements have cache control public some have private some an etag it is not very consistant.

davidyack commented 7 years ago

Yeah I agree the web resources or any JS file etc will be impacted, but have you seen this on a Web API get request? Thx Dave

ghost commented 7 years ago

well, yes, since I retrieve webresourse sometimes like that :D

davidyack commented 7 years ago

ok, will research a little more- either way should add 304 when we add conditional, just want to understand if there are other scenarios that will return it that need to be considered

thx