I am developing an iOS app that mainly loads my web pages in WKWebView.
Things were fine so far before I start facing a weird issue with one of the CSS file not loading.
The font-awesome.css file is not loading, generally it gets loaded on the very first page call. In my knowledge nothing has been changed on the server side that could affect loading of font-awesome.css file.
I am intercepting request by implementing following function in iOS app code. But for the first request I just do decisionHandler(.allow) because I don't want any interception for the first request.
func webView(_ webView: WKWebView, decidePolicyFor navigationAction: WKNavigationAction,
decisionHandler: @escaping (WKNavigationActionPolicy) -> Swift.Void) {
// For the first request it will go as is
decisionHandler(.allow)
}
Once the first page gets loaded on WKWebView the font-awesome.css file didn't get loaded hence some font icons are shown as squares on the page.
After spending some time on this issue I tried to put a delay on calling decisionHandler(.allow) as follows and then it starts loading the font-awesome.css file:
DispatchQueue.main.asyncAfter(deadline: .now() + 0.150) {
// I just added a delay of 150 ms and it starts loading the css file.
decisionHandler(.allow)
}
For me currently its very confusing to figure out the relation between putting a delay and loading of the css file.
I need suggestion on this behavior why its happening or is there anything else due to which this is happening and I am just doing a work around by putting a delay.
Some more updates:
I have an Android app also that is loading same web pages in WebView and that is working fine.
I check the IIS logs by sending the request with and without putting the delay. With the delay I an clearly see in IIS logs that it loads the font awesome as follows, but in without delay I don't see this entry in IIS logs:
2020-11-23 13:44:36 10.100.2.72 GET /Content/fonts/fontawesome-webfont.woff2 v=4.5.0 80 - 10.100.0.111 ....