Webview cache



I’m starting using Electron for a python frontend and I have 2 webviews in my main html file (one for a left panel and other one for the right panel)
I need webviews because in the right panel I can load pages from my embeded local python webserver or page from external website.
For now I used src attribute to update displayed page of my right panel, but cache is really agressive and changes on those pages are not displayed when i launch again my electron app. I need to clear manually Cache dir content in my home dir to see changes.

I tryed a lot of thing found on internet, I read many times electron documentation but I found no solution to my problem.
I saw there is an option in webview loadUrl (in extra options “pragma no-cache”) but I didn’t find a way to load webview content using this loadURL function.
I also saw that disabling cache is not supported on electron.
So my question is : is there a solution to disable completely webview cache and is there somebody that can explain it to me :slight_smile:

Thank you very much for you help.

My files:

  • My main.js is exactly the same that on default example except that I added pragma no-cache on mainWindow.loadURL() function.

const electron = require(‘electron’)
// Module to control application life.
const app = electron.app
// Module to create native browser window.
const BrowserWindow = electron.BrowserWindow
// external browser
const shell = require(‘electron’).shell;

const path = require(‘path’)
const url = require(‘url’)

var log = require(‘electron-log’);

// Keep a global reference of the window object, if you don’t, the window will
// be closed automatically when the JavaScript object is garbage collected.
let mainWindow

function createWindow () {
// Create the browser window.
mainWindow = new BrowserWindow({width: 800, height: 600})

// and load the index.html of the app.
    //pathname: path.join(__dirname, 'devices.html'),
    pathname: path.join(__dirname, 'index.html'),
    protocol: 'file:',
    slashes: true
}), {"extraHeaders" : "pragma: no-cache\n"})

// Open the DevTools.

// Emitted when the window is closed.
mainWindow.on('closed', function () {
    // Dereference the window object, usually you would store windows
    // in an array if your app supports multi windows, this is the time
    // when you should delete the corresponding element.
    mainWindow = null


// This method will be called when Electron has finished
// initialization and is ready to create browser windows.
// Some APIs can only be used after this event occurs.
app.on(‘ready’, createWindow)

  • My main index.html:
<webview id="left" style="width:640px; height:480px"></webview>
<webview id="right" style="width:640px; height:480px"></webview>
  • And finally my renderer.js

onload = function() {
var left = document.querySelector(’#left’);
var right = document.querySelector(’#right’);

left.src = 'http://localhost:5610/devices.html'
right.src = 'http://localhost:5610/homepage.html'

/*right.addEventListener('dom-ready', () => {
}) */



As my problem doesn’t inspire anybody unfortunately, I’m trying to change design of my application:
Instead having minimal code in electron (2 webviews) with external python webserver to serve pages I serve my pages with angularjs (v1) as singlepage app using ngroute directly in electron.

I’m facing now another problem to open preferences page from main application menu. All solutions I tried did nothing:

  • test1: I declare app menu in electron startup file (main.js) and use ipc to communicate with controller in renderer file. It call successfully my controller (console.log) but $location.path does nothing.
  • test2: I declare app menu directly in controller and call directly controller function that execute $location.path and nothing happens too

For the 2 solutions I had no js error in electron output or in console.
A call of the controller “openPage” function (that execute $location.path) in another page is working fine using ng-click

I don’t understand what happen :frowning:

Any help would be very very appreciated.



Did you tried this

win.webContents.session.clearCache(function(){console.log('cleared all cookies ');});

Or attach your webview with a session and clear that session when ever you are you are refreshing the page

"<div class='webview'><webview class='tabs-pane active' partition='persist:webviewsession' src='www.google.com' ></webview></div>";



is your problem solved? I tried clear everything manually from devTool > application > clear all but cache still is not removed,