6

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?

Daniel Prosianikov
  • 100
  • 1
  • 1
  • 10

2 Answers2

17

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.

Alexander Leithner
  • 3,169
  • 22
  • 33
1

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

nsrCodes
  • 625
  • 10
  • 25