Discuții » Dezvoltare

Replacing JS files on page. Load the page ignoring the hash

§
Postat în: 23-12-2021
Editat în: 23-12-2021

I recently created a script that replaces any JS file on the site (https://greasyfork.org/ru/scripts/437488-easy-script-replacement-example). But sometimes it may not work if the document is loaded from the hash. I solve this problem this way, but I'm not sure about this solution and it doesn't seem stable to me.

// if document was loaded from hash HTML may not be replaced
var firstLoad = localStorage.getItem('firstLoad');
if (!firstLoad === '1') {
....localStorage.setItem('firstLoad', '1');
....// reloading with hash ignoring
....return window.location.reload(true)
} else {
....localStorage.removeItem(firstLoad);
}

§
Postat în: 23-12-2021

!firstLoad === '1' is always false

§
Postat în: 23-12-2021

if document was loaded from hash

And what does that mean? You mean cache maybe?

§
Postat în: 23-12-2021

You mean cache maybe?

Maybe.

§
Postat în: 23-12-2021
!firstLoad === '1' is always false

indeed

Postează un raspuns

Autentifică-te pentru a posta un răspuns.