議論 » 開発

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

§
投稿日: 2021/12/23
編集日: 2021/12/23

I recently created a script that replaces any JS file on the site (https://greatest.deepsurf.us/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);
}

§
投稿日: 2021/12/23

!firstLoad === '1' is always false

§
投稿日: 2021/12/23

if document was loaded from hash

And what does that mean? You mean cache maybe?

§
投稿日: 2021/12/23

You mean cache maybe?

Maybe.

§
投稿日: 2021/12/23
!firstLoad === '1' is always false

indeed

返信を投稿

返信を投稿するにはログインしてください。