How to disable http cache for electron app after packaging to .exe using electron-packager
Asked Answered
C

2

7

I have an electron app, that loads some css's from spring boot server. When I run app from npm from sources, I can run as

ng build && electron . --disable-http-cache

and it works without the cache. If I build my app with electron-packager to app.exe, how can I disable cache. Start .exe-file with --disable-http-cache doesn't work

UPDATE The only approach that works is to clear cache from main process before app loads the page. But is there any another way to disable cache?

Coherent answered 5/3, 2019 at 8:13 Comment(0)
G
19

Another possibility is to use Electron's commandLine.appendSwitch () in the main process on the app object, right before anything gets executed:

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

app.commandLine.appendSwitch ("disable-http-cache");
// any other main process code

This will append --disable-http-cache to Chromium's command line, just like appending it to the electron command would. When having this in code, you do no longer have to run your app with appending this switch as it will automatically be added.

Giselegisella answered 6/3, 2019 at 15:1 Comment(0)
L
2

You can also add a no-cache header inside loadURL() of the route that is requesting the css (or even the root route)

webContents.loadURL(url, {"extraHeaders" : "pragma: no-cache\n"})

A complete mini example gist

Lorilee answered 8/3, 2022 at 1:17 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.