Hi
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
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 mainWindowfunction createWindow () {
// Create the browser window.
mainWindow = new BrowserWindow({width: 800, height: 600})
mainWindow.maximize();// and load the index.html of the app. mainWindow.loadURL(url.format({ //pathname: path.join(__dirname, 'devices.html'), pathname: path.join(__dirname, 'index.html'), protocol: 'file:', slashes: true }), {"extraHeaders" : "pragma: no-cache\n"}) // Open the DevTools. mainWindow.webContents.openDevTools() // 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', () => { }) */
};