Data not updated when back by back button of browser

Hi guys, I act upvoting a post on the home page, then go to another page, and then go back by pressing the back button of my browser. Maybe the browser caches data. The post that I upvoted before did not change, and when I checked the data, it was still old data. Only reloading the page will update the data.
Is there any way to fix this?
I try to use pageshow event to update post list but not working

$(window).off('pageshow').on('pageshow', async function (event) {
        if ((event.persisted || (performance.getEntriesByType("navigation")[0]?.type === "back_forward"))) {
            const params = utils.params();
            const query = {
                page : 1,
                ...params,
                _t: new Date().getTime()
            }
            await api.get('/search/keyword' , query, function (err, data) {
                if(err) return;
                app.parseAndTranslate('partials/posts_list', { posts: data?.posts }, function (html) {
                    $('.topics-list').html(html);
                });
            })
        }
    });
2

Log in to comment