camelaissani / frontexpress

An Express.js-Style router for the front-end
https://frontexpressjs.com
MIT License
261 stars 12 forks source link

Does Service Worker API can be used to listen emitted/received AJAX requests by the application? #11

Open camelaissani opened 7 years ago

camelaissani commented 7 years ago

Currently these methods application.http(Get|Post...)(request, success, failure) are provided to make AJAX calls. Unfortunately, those methods force developers to use a custom API for making AJAX calls rather than using the standard ones (Fetch, XHR).

May be a solution to avoid this situation is to use the Service Workers? As the SW can play the role of proxy, we can relay on it to listen requests emitted by the application. Thus, the AJAX requests can be invoked from any frameworks (standard JS API, JQuery...) rather than using the ones provided by FrontExpress.

camelaissani commented 7 years ago

It looks like there is a limitation with Synchronous XHR requests https://stackoverflow.com/questions/35879844/can-service-workers-respond-to-synchronous-xhr-requests

camelaissani commented 7 years ago

Another cons point:

Service workers only run over HTTPS, for security reasons. Having modified network requests wide open to man in the middle attacks would be really bad. In Firefox, Service Worker APIs are also hidden and cannot be used when the user is in private browsing mode.

from: https://developer.mozilla.org/en/docs/Web/API/Service_Worker_API