开发者

caching on load webView from local file + JS on Mac

开发者 https://www.devze.com 2023-03-08 01:29 出处:网络
I have an external folder with html files and JS files. I have a problem to make my webView to work with updated version of this folder. I mean if I change JS file it doesn\'t takes the updated versio

I have an external folder with html files and JS files. I have a problem to make my webView to work with updated version of this folder. I mean if I change JS file it doesn't takes the updated version and works always开发者_运维问答 with the old version. How do I prevent this "caching"? I'm running the application from Xcode and even after I exit Xcode and relaunch the application it works with old version.

Thanks for help


This code is supposed to disable caching on WebKit:

    [[WebPreferences standardPreferences] setCacheModel:WebCacheModelDocumentViewer];
    [[WebPreferences standardPreferences] setUsesPageCache:NO];

    NSURLCache *sharedCache = [[NSURLCache alloc] initWithMemoryCapacity:0 diskCapacity:0 diskPath:nil];
    [NSURLCache setSharedURLCache:sharedCache];
    [sharedCache release];
    sharedCache = nil;

It helped me anyway


If you never want caching, append the current timestamp the end of the url of your assets.

"myJsFile.js?12378127389"

This makes the url different every time an causes the cache check to miss, which means it will reload it from disk.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号