使用电子打包器打包到 .exe 后如何禁用电子应用程序的 http 缓存

Dan*_*kov 5 electron electron-packager

我有一个电子应用程序,它从 Spring Boot 服务器加载一些 css。当我从源代码运行 npm 应用程序时,我可以作为

ng build && electron . --disable-http-cache
Run Code Online (Sandbox Code Playgroud)

它在没有缓存的情况下工作。如果我使用电子打包器将我的应用程序构建到 app.exe,我该如何禁用缓存。使用 --disable-http-cache 启动 .exe 文件不起作用

更新 唯一有效的方法是在应用加载页面之前从主进程中清除缓存。但是有没有其他方法可以禁用缓存?

Ale*_*ner 12

另一种可能性是commandLine.appendSwitch ()app对象的主进程中使用 Electron ,在执行任何操作之前:

const { app } = require ("electron");

app.commandLine.appendSwitch ("disable-http-cache");
// any other main process code
Run Code Online (Sandbox Code Playgroud)

这将附加--disable-http-cache到 Chromium 的命令行,就像将它附加到electron命令一样。当在代码中使用它时,您不再需要通过附加此开关来运行您的应用程序,因为它将自动添加。