fltk-rs / fltk-webview

webview functionality for embedded fltk windows
MIT License
47 stars 7 forks source link

How to clean cache #12

Closed dongjian closed 2 years ago

dongjian commented 2 years ago

I set up a file server locally. When I change the HTML content, the WebView does not change. (It works fine on the browser). Even if I delete the file, the WebView still works fine. I tried to restart the computer and delete target cargo run again ,but the cache was still there.I need to modify the file name, and then modify the url. Webview to appear the new content . any help?

dongjian commented 2 years ago

by the way . is there any method can know when the webview is already load finish . I need to eval some js at the begining of the web. I tried the init method . but it not woring . I do it now like the code below

Message::WebServerAlready => {
                    println!("http server READY !");

                    wv.navigate("http://127.0.0.1:8080/map.html");
                    let sender = s.clone();
                    tokio::spawn(async move {
                        tokio::time::sleep(Duration::from_millis(100)).await;
                        sender.send(Message::SetDefaultMap);
                    });
                }
                Message::SetDefaultMap => {
                    let test = get_map_param_json(
                        None,
                        0.0,
                        "OpenStreetMap".to_string(),
                    );

                    wv.eval(&get_evl_str(test));
                }
MoAlyousef commented 2 years ago

The webview doesn’t detect changes to files, you would need some notification system (like notify-rs) to notify the program of changes then reload the webview (call set_html or navigate). Regarding init, are you calling it before the set_html or navigate commands? What isn’t working? What OS?

dongjian commented 2 years ago

OS: windows 10 Now I need to delete C:\Users\user\AppData\Local\Packages to clean the cache. Otherwise the WebView won't change . I use navigate

dongjian commented 2 years ago

The webview doesn’t detect changes to files, you would need some notification system (like notify-rs) to notify the program of changes then reload the webview (call set_html or navigate).

Sorry , My english is not good . You may have misinterpreted my meaning .

  1. I have a map.html : <div>123</div>
  2. cargo run . then the webview show 123
  3. close progrom . change map.html to <div>456</div>
  4. cargo run . the webview still show 123
  5. remove all C:\Users\user\AppData\Local\Packages .
  6. cargo run . the webview show 456
MoAlyousef commented 2 years ago

How are you accessing map.html, is it via some GET request? In that case yes, caching happens in the webview’s system cache directory. You can use query strings or meta tags to disable caching during development: https://www.geeksforgeeks.org/how-to-clear-cache-memory-using-javascript/

dongjian commented 2 years ago

Thanks.Because I deleted all the files in "AppData\Local\Packages" earlier. After I rebooted my computer. Calling webView crashes. So I re-installed the WebView2 Runtime for Windows(MicrosoftEdgeWebView2RuntimeInstallerX64.exe). Now even though I didn't use the method you mentioned above. Can work normally and update the page normally .So May be it's windows webview runtime bug.

dongjian commented 2 years ago

I tried again. It doesn't refresh properly again.

<html>

<head>
    <meta http-equiv='cache-control' content='no-cache'>
    <meta http-equiv='expires' content='0'>
    <meta http-equiv='pragma' content='no-cache'>
    <meta charset="UTF-8">
      .........

<body>
    <div id="root"></div>
    <script type="text/javascript" src="map.js?version = 1.2"></script>
</body>

I do like the article . but it still load the cache. even if i delete the map.html

I checked the output of the server. Does not request my server when the cache exists

[2021-12-02T07:01:37Z INFO  actix_web::middleware::logger] 127.0.0.1:50142 "GET /car.svg HTTP/1.1" 404 0 "http://127.0.0.1:8080/map.html" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.55 Safari/537.36 Edg/96.0.1054.41" 0.000226
[2021-12-02T07:01:37Z INFO  actix_web::middleware::logger] 127.0.0.1:50142 "GET /favicon.ico HTTP/1.1" 404 0 "http://127.0.0.1:8080/map.html" "Mozilla/5.0 (Windows 
NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.55 Safari/537.36 Edg/96.0.1054.41" 0.000195

I have to change the filename to avoid the cache problem . after change the file name to 123.html 123.js . the server out put

[2021-12-02T07:10:01Z INFO  actix_web::middleware::logger] 127.0.0.1:49689 "GET /123.html HTTP/1.1" 200 20150 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.55 Safari/537.36 Edg/96.0.1054.41" 0.006475
[2021-12-02T07:10:01Z INFO  actix_web::middleware::logger] 127.0.0.1:49689 "GET /123.js?version=1.3 HTTP/1.1" 200 2992807 "http://127.0.0.1:8080/123.html" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.55 Safari/537.36 Edg/96.0.1054.41" 0.104495
[2021-12-02T07:10:01Z INFO  actix_web::middleware::logger] 127.0.0.1:49689 "GET /car.svg HTTP/1.1" 404 0 "http://127.0.0.1:8080/123.html" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.55 Safari/537.36 Edg/96.0.1054.41" 0.000155
[],"baiduPosArr":[],"gSenserArr":[],"maxSpeed":0.0,"minSpeed":0.0,"distance":0.0},"dicNMEA":{}}
[2021-12-02T07:10:09Z INFO  actix_web::middleware::logger] 127.0.0.1:49709 "GET /favicon.ico HTTP/1.1" 404 0 "http://127.0.0.1:8080/123.html" "Mozilla/5.0 (Windows 
NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.55 Safari/537.36 Edg/96.0.1054.41" 0.000155