• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

How to Force an Automatic Refresh on Single Page App

Contributor ,
Apr 17, 2019 Apr 17, 2019

Copy link to clipboard

Copied

Hi all,

Thanks in advance for taking a look at this.

I am trying to create a force refresh at one point in my Single Page App.

My general problem is that when I update the page on the server - the changes do not appear because the cache needs to be refreshed. So I am trying to refresh automatically somehow.

So, I have a link on the page that has an onclick="javascript:main()" which triggers a function that sets some vars and then goes to a section of the Page like this:

Part of the functions is:

---

// set vars etc......

// make time stamp for query strings force auto update

var tm = new Date().getTime();

window.location.replace("#main1?tm=" + tm);

---

example result:

https://mysite.com/test.html#main1?tm=1555539113122

Basic question: does the tm(timestamp always different) force a refresh? like...

https://mysite.com/test.html?tm=1555539113122

I am not sure it is really working. maybe because the xxx.html#main comes before the ?tm=xxx?

My question is this the correct way to force an automatic refresh to happen or is there a better way?

Views

1.7K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
May 01, 2019 May 01, 2019

Copy link to clipboard

Copied

Hi - Still curious about this - thanks

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 01, 2019 May 01, 2019

Copy link to clipboard

Copied

The normal way is to refresh the data shown on the page using Ajax functions. No page refresh necessary.

Wappler, the only real Dreamweaver alternative.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
May 03, 2019 May 03, 2019

Copy link to clipboard

Copied

Hi Ben,

Thanks for the help.

Well I am using ajax for data - however in my case, I am editing / updating some of the base html / css etc. and that is what sometimes doesn't update/refresh.

One person reminded me that maybe the server is caching pages and maybe that is part of the problem? I will check with the server techs soon.

Dave

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
May 02, 2019 May 02, 2019

Copy link to clipboard

Copied

Are you using a framework or are you using vanilla JavaScript?

The timestamp is a traditional way to force anything performing a 'load' (AJAX, browser, etc) to download it again since the number in cache will never match.

You said you are changing some values but what 'exactly' do you expect to happen when you click and change the hash? Frameworks often have their own 'router' and use the #path/to/var setup to redirect SPAs between different controller/views. We need to know more however.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
May 03, 2019 May 03, 2019

Copy link to clipboard

Copied

LATEST

Hi sinious,

In this case just vanilla javascript. As mentioned to Ben -  I am editing / updating some of the base html / css etc. and that is what sometimes doesn't update/refresh.

I will check with server techs soon to see about page caching.

Do you think this is ok to do with the #main element in the url or might that mess things up?

example result:

https://mysite.com/test.html#main1?tm=1555539113122

( the xxx.html#main comes before the ?tm=xxx? ) is this ok?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines