Ever wanted to create a browser console log that persists after a page reloads? Sure, that isn’t a problem if you enable the “preserve log” option in your developer console, but hear me out.

Say you have a JavaScript framework with a development server that usually hot-reloads when you update files while the server is running. In the few cases where hot reloading isn’t possible and the page has to fully reload, you want to warn your users and explain why this is happening. It’d be nice to just log a warning to the console with console.warn(), but the moment it shows up in the console, wouldn’t you know, the page reloads, and the browser clears it. Even if your user is eagle-eyed enough to notice your warning flash on the screen for a fraction of a second, it certainly isn’t there long enough to actually read.

You could say that if any of your users don’t know where the “preserve log” button is then that’s their problem, but you’re kinder than that. You’d rather help them fall into the Pit of Success.

#nextjs #javascript #console-log #web-development #web-design

Make a Browser Console Log Wait for a Page Reload
1.15 GEEK