How to cache content in UIWebView for faster loading later on?

后端 未结 4 987
醉话见心
醉话见心 2020-11-27 15:02

I notice that the iphone safari caches content so that your page load for later is much faster much like a desktop browser. So take mobile gmail web page for example, the fi

4条回答
  •  -上瘾入骨i
    2020-11-27 15:26

    I've done a couple of apps that cache pages to the Documents folder, then compare the time-stamps of the cached & web pages before loading the new web page. So the basic flow is:

    if (fileIsInCache)
        if (cacheFileDate > webFileDate)
            getCachedFile
        else
            getFileFromWeb
            saveFileToCache
    else
        getFileFromWeb
        saveFileToCache
    
    stuffFileIntoUIView
    
    maybeReduceCache
    

    You still have to hit the web to get the headers, but that's typically much faster than downloading a whole page/image/file.

提交回复
热议问题