Electron App takes a lot of time to Load


#1

Electron version:0.37.2
Operating system:Windows
I have created an electron app as a wrapper of a website.
Below is the code:
Dev Package.json:
{
“devDependencies”: {
“electron-builder”: “^3.27.0”,
“electron-prebuilt”: “^0.37.2”
},
“build”: {
“app-bundle-id”: “EnterpriseSearch”,
“app-category-type”: “public.app-category.productivity”,
“ignore”:“node_modules/electron-osx-sign-tf,node_modules/archiver”,
“win”: {
“iconUrl”: “http://eatodo.s3.amazonaws.com/icon.ico
}
},
“scripts”: {
“postinstall”: “install-app-deps”,
“start”: “electron ./app --enable-logging”,
“dev”: “NODE_ENV=‘development’ npm run start”,
“dist”: “npm run dist:win64”,
“dist:win64”: “build --platform win32 --arch x64”
}
}

Application Package.json:
{
“name”:“EnterpriseSearch”,
“version”:“0.1.0”,
“main”:“main.js”,
“author”:“TCS”,
“description”: “This is a desktop app for Enterprise Search.”
}

Main.js:
if (require(‘electron-squirrel-startup’)) return;
var app = require(‘app’);
// this should be placed at top of main.js to handle setup events quickly
if (handleSquirrelEvent()) {
// squirrel event handled and app will exit in 1000ms, so don’t do anything else
return;
}

function handleSquirrelEvent() {
if (process.argv.length === 1) {
return false;
}

const ChildProcess = require(‘child_process’);
const path = require(‘path’);

const appFolder = path.resolve(process.execPath, ‘…’);
const rootAtomFolder = path.resolve(appFolder, ‘…’);
const updateDotExe = path.resolve(path.join(rootAtomFolder, ‘Update.exe’));
const exeName = path.basename(process.execPath);

const spawn = function(command, args) {
let spawnedProcess, error;

try {
spawnedProcess = ChildProcess.spawn(command, args, {detached: true});
} catch (error) {}

return spawnedProcess;
};

const spawnUpdate = function(args) {
return spawn(updateDotExe, args);
};

const squirrelEvent = process.argv[1];
switch (squirrelEvent) {
case ‘–squirrel-install’:
case ‘–squirrel-updated’:
// Optionally do things such as:
// - Add your .exe to the PATH
// - Write to the registry for things like file associations and
// explorer context menus

// Install desktop and start menu shortcuts
spawnUpdate([’–createShortcut’, exeName]);

setTimeout(app.quit, 1000);
return true;

case ‘–squirrel-uninstall’:
// Undo anything you did in the --squirrel-install and
// --squirrel-updated handlers

// Remove desktop and start menu shortcuts
spawnUpdate([’–removeShortcut’, exeName]);

setTimeout(app.quit, 1000);
return true;

case ‘–squirrel-obsolete’:
// This is called on the outgoing version of your app before
// we update to the new version - it’s the opposite of
// --squirrel-updated

app.quit();
return true;
}
};

var BrowserWindow = require(‘browser-window’);

var win = null;

//app.commandLine.appendSwitch(‘ignore-certificate-errors’);
//app.commandLine.appendSwitch(‘disable-http-cache’);
//app.commandLine.appendSwitch(“disable-renderer-backgrounding”);
app.on(‘ready’, function() {
win = new BrowserWindow({webPreferences: { nodeIntegration: false}});

win.loadUrl(‘https://enterprisesearch.ultimatix.net/enterprisesearch/’);

win.on(‘closed’, () => {
// 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.
win = null;
});
});

// Quit when all windows are closed.
app.on(‘window-all-closed’, () => {
// On OS X it is common for applications and their menu bar
// to stay active until the user quits explicitly with Cmd + Q
if (process.platform !== ‘darwin’) {
app.quit();
}
});

I have build the installer using electron builder.
But final exe takes around 1 minute to load and display the page.
How can I improve it’s performance.


#2

I’m not in a position to help you with your performance issues, but please consider fencing your code with backticks as described here. It would make it much easier to read for the people with the ability to assist you.


#3

Oh…Sure. Will remember this next time. is there any suggestion on Electron app performance?


#4

My App takes around 1 minute to load. is it the expected time to load an electron app?


#5

When you say ‘load’, where are you loading from? Is it via command line or have you packaged the app?

My app is instant from command line and only takes a couple of seconds, once packaged, to install and start up.


#6

oh…That’s great. I am loading from installer, final exe built from electron - builder. When I click it takes around one minute to load. Have you done any specific setting to reduce load time?


#7

How long does your unpackaged app take to load? Regardless, you need to profile your app to see where all that time is going, there’s no point trying to guess.


#8

Can you edit your original post with the backticks ( ` ) so you can get more help?


#9

@enlight… Un packaged also take almost same time. Even electron demo app also takes similar time. Any idea why?
@sargasdev - I am able to edit the subject, but not the description.


#10

If you click the ellipsis button:

Then you get a bigger menu that includes the option to edit the body text of your post: