You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@cordova.apache.org by GitBox <gi...@apache.org> on 2020/12/15 03:29:08 UTC

[GitHub] [cordova-android] jsbay opened a new issue #1143: [HELP] How to intercept requests to local files

jsbay opened a new issue #1143:
URL: https://github.com/apache/cordova-android/issues/1143


   I am a web developer and I plan to package my web page files into an apk, but there is a js file in my file that will go to the Internet to request a large number of font files. I want to know how I should detect network requests. Forward these requests to the local (local cache of font files).


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@cordova.apache.org
For additional commands, e-mail: issues-help@cordova.apache.org


[GitHub] [cordova-android] breautek closed issue #1143: [HELP] How to intercept requests to local files

Posted by GitBox <gi...@apache.org>.
breautek closed issue #1143:
URL: https://github.com/apache/cordova-android/issues/1143


   


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@cordova.apache.org
For additional commands, e-mail: issues-help@cordova.apache.org


[GitHub] [cordova-android] jsbay commented on issue #1143: [HELP] How to intercept requests to local files

Posted by GitBox <gi...@apache.org>.
jsbay commented on issue #1143:
URL: https://github.com/apache/cordova-android/issues/1143#issuecomment-745695856


   > Is there a reason why you are requesting them over the internet? You really should just package those font files locally and request them locally instead of them.
   
   This is the online preview of `onlyoffice` used in my app. `Onlyoffice` needs to load a large number of font packages to work properly. The loading action is issued in the js script of **onlyoffice**, so I think the best way is to intercept these font requests globally and use Local font package instead.


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@cordova.apache.org
For additional commands, e-mail: issues-help@cordova.apache.org


[GitHub] [cordova-android] jsbay commented on issue #1143: [HELP] How to intercept requests to local files

Posted by GitBox <gi...@apache.org>.
jsbay commented on issue #1143:
URL: https://github.com/apache/cordova-android/issues/1143#issuecomment-745032257


   Or is there a way to expand the cache capacity of the apk? 
   Now the font file has set `Response Headers`,like: 
   ```
   HTTP/1.1 200 OK
   Server: nginx
   Date: Tue, 15 Dec 2020 03:33:06 GMT
   Content-Type: application/octet-stream
   Last-Modified: Fri, 11 Dec 2020 07:50:37 GMT
   Vary: Accept-Encoding
   ETag: W/"5fd324cd-df70c"
   Expires: Wed, 15 Dec 2021 03:33:06 GMT
   Cache-Control: max-age=31536000
   Content-Encoding: gzip
   ```
   It will be cached in chrome browser by default
   ![](http://img.baymax.club/WeChat295688116e4de42652764891d8c84e88.png)
   But in the packaged apk, it seems that only a part of it is cached. 
   Does the apk limit the size of the cache capacity?
   If so, can I modify this limit? How?


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@cordova.apache.org
For additional commands, e-mail: issues-help@cordova.apache.org


[GitHub] [cordova-android] breautek commented on issue #1143: [HELP] How to intercept requests to local files

Posted by GitBox <gi...@apache.org>.
breautek commented on issue #1143:
URL: https://github.com/apache/cordova-android/issues/1143#issuecomment-745291431


   Is there a reason why you are requesting them over the internet? You really should just package those font files locally and request them locally instead of them.
   
   Your app should work well enough offline. Your app may have parts that require an internet connection, but it should at least be able to load up your base UI code. You will obviously be missing your font files (something a user may see as a buggy app if the font randomly changes) if the user tries using your app without an internet connection.
   
   To answer your question, it isn't easy to "intercept" a request in JS. A normal way of doing this would be via Service Workers, however they don't work in the android webview. You might be able to do this via creating your own [plugin](https://cordova.apache.org/docs/en/latest/guide/hybrid/plugins/) and provide an implementation for:
   
   https://github.com/apache/cordova-android/blob/55feadff0519fa294be34c22ff6fbb913efd1b48/framework/src/org/apache/cordova/CordovaPlugin.java#L292-L319
   
   But the challenge you'll face is "How do you detect if the file is in the chrome cache, and if so how do you obtain it so that you can read and serve it." At this point you're utilising a private implementation detail of the chrome webview, therefore it would be easier and more stable just to bundle your assets with your APK.
   
   Despite my effort of trying to give you a detailed answer, Apache Cordova doesn't provide support in GitHub Issues therefore I'll be closing this ticket. We use GitHub Issues are for tracking bugs or feature requests only. If you require further support, I do invite you to use our [Slack Community](http://slack.cordova.io/) instead.


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@cordova.apache.org
For additional commands, e-mail: issues-help@cordova.apache.org