# How can I receive the current and published weweb live version with JavaScript?

**URL:** <https://community.weweb.io/t/how-can-i-receive-the-current-and-published-weweb-live-version-with-javascript/9720>\
**Category:** Developer corner\
**Created:** [July 15, 2024, 6:27am UTC](https://community.weweb.io/t/how-can-i-receive-the-current-and-published-weweb-live-version-with-javascript/9720 "2024-07-15T06:27:34Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![stefan](https://avatars.discourse-cdn.com/v4/letter/s/bbce88/32.png) [@stefan](https://community.weweb.io/u/stefan)\
**Post date:** [July 15, 2024, 6:27am UTC](https://community.weweb.io/t/how-can-i-receive-the-current-and-published-weweb-live-version-with-javascript/9720/1 "2024-07-15T06:27:34Z")

</div>

Hi there,

How can I get the current application version number (of our web app) and the published application version using JavaScript code? I need to know this information so I can write a JavaScript script that checks every 15 minutes if a new update is available, and shows the user a popup message asking them to refresh the web page.

Thanks,  
Stefan

---

<div class="post-metadata">

**Author:** ![Broberto](https://sea2.discourse-cdn.com/flex016/user_avatar/community.weweb.io/broberto/32/5918_2.png) [@Broberto](https://community.weweb.io/u/Broberto)\
**Post date:** [July 15, 2024, 6:53am UTC](https://community.weweb.io/t/how-can-i-receive-the-current-and-published-weweb-live-version-with-javascript/9720/2 "2024-07-15T06:53:16Z")

</div>

This can be done simply with pwa, are you self hosting?

---

<div class="post-metadata">

**Author:** ![MichaelLovell](https://sea2.discourse-cdn.com/flex016/user_avatar/community.weweb.io/michaellovell/32/2157_2.png) [@MichaelLovell](https://community.weweb.io/u/MichaelLovell)\
**Post date:** [July 15, 2024, 7:04am UTC](https://community.weweb.io/t/how-can-i-receive-the-current-and-published-weweb-live-version-with-javascript/9720/3 "2024-07-15T07:04:25Z")

</div>

Here is a snippet I use in custom js On App Load.

You can access the version number in your deployments. Save it somewhere and then check the cacheVersion against the deployed version number.

```auto
// Get the cache version of the application
let version = window.wwg_cacheVersion;

// Update the variable ['cacheVersion]
wwLib.wwVariable.updateValue('80e49d79-......-8cd291322232', version);

console.log("version: ", version)

return version;

```

---

<div class="post-metadata">

**Author:** ![stefan](https://avatars.discourse-cdn.com/v4/letter/s/bbce88/32.png) [@stefan](https://community.weweb.io/u/stefan)\
**Post date:** [July 15, 2024, 7:27am UTC](https://community.weweb.io/t/how-can-i-receive-the-current-and-published-weweb-live-version-with-javascript/9720/4 "2024-07-15T07:27:30Z")

</div>

Hi there,

Thank you for your answer. I will test it here.

Thanks,  
Stefan

---

<div class="post-metadata">

**Author:** ![stefan](https://avatars.discourse-cdn.com/v4/letter/s/bbce88/32.png) [@stefan](https://community.weweb.io/u/stefan)\
**Post date:** [July 15, 2024, 8:12am UTC](https://community.weweb.io/t/how-can-i-receive-the-current-and-published-weweb-live-version-with-javascript/9720/5 "2024-07-15T08:12:39Z")

</div>

Hi @MichaelLovell

I tried to use your suggestion. However, I do not see a way to determine the current live app version when the user is still using the old version.

@Broberto  
Yes it is a self hosting. A code suggestion on PWA will be welcome.

Thanks,  
Stefan

---

<div class="post-metadata">

**Author:** ![stefan](https://avatars.discourse-cdn.com/v4/letter/s/bbce88/32.png) [@stefan](https://community.weweb.io/u/stefan)\
**Post date:** [July 15, 2024, 9:05am UTC](https://community.weweb.io/t/how-can-i-receive-the-current-and-published-weweb-live-version-with-javascript/9720/6 "2024-07-15T09:05:14Z")

</div>

Hi there,

Another question, how can I edit the default PWA code from weweb to add my custom code for checking the app version number.

Thanks,  
Stefan

---

<div class="post-metadata">

**Author:** ![Broberto](https://sea2.discourse-cdn.com/flex016/user_avatar/community.weweb.io/broberto/32/5918_2.png) [@Broberto](https://community.weweb.io/u/Broberto)\
**Post date:** [July 15, 2024, 9:31am UTC](https://community.weweb.io/t/how-can-i-receive-the-current-and-published-weweb-live-version-with-javascript/9720/7 "2024-07-15T09:31:59Z")

</div>

You can edit the service worker to trigger a workflow on app updated, it’s really simple and ChatGPT should be able to do this for you. You should be able to make this with the GPT, [in my case, it should be enough for you to go till the step 3. and do the banner in step 4. in WeWeb.](https://chatgpt.com/share/17193408-80fe-4575-9084-c1c80b063eef)

---

<div class="post-metadata">

**Author:** ![MichaelLovell](https://sea2.discourse-cdn.com/flex016/user_avatar/community.weweb.io/michaellovell/32/2157_2.png) [@MichaelLovell](https://community.weweb.io/u/MichaelLovell)\
**Post date:** [July 15, 2024, 10:06am UTC](https://community.weweb.io/t/how-can-i-receive-the-current-and-published-weweb-live-version-with-javascript/9720/8 "2024-07-15T10:06:17Z")

</div>

For context, I’m using self hosting. When I make a deployment I save a deployment log in my db with the version number. Then I use a workflow On App Load to check whether the cacheVersion matches the latest deployment version. If false, show a a banner message or force a refresh.

---

<div class="post-metadata">

**Author:** ![stefan](https://avatars.discourse-cdn.com/v4/letter/s/bbce88/32.png) [@stefan](https://community.weweb.io/u/stefan)\
**Post date:** [July 15, 2024, 11:01am UTC](https://community.weweb.io/t/how-can-i-receive-the-current-and-published-weweb-live-version-with-javascript/9720/9 "2024-07-15T11:01:01Z")

</div>

Hi there,

@Broberto  
In ChatGPT, is step 3 not needed for weweb? It uses the default service worker code from weweb.

@MichaelLovell

> When I make a deployment I save a deployment log in my db with the version number.  
> So you use a third-party service like Xano to fetch the version number? I want a solution without any dependencies.

Thanks,  
Stefan

---

<div class="post-metadata">

**Author:** ![Broberto](https://sea2.discourse-cdn.com/flex016/user_avatar/community.weweb.io/broberto/32/5918_2.png) [@Broberto](https://community.weweb.io/u/Broberto)\
**Post date:** [July 15, 2024, 11:12am UTC](https://community.weweb.io/t/how-can-i-receive-the-current-and-published-weweb-live-version-with-javascript/9720/10 "2024-07-15T11:12:41Z")

</div>

What I would do is use my prompt, and paste your service worker there for the ChatGPT to alter it accordingly. The prompt I shared is just an example, it’s not in a WeWeb context, even though very similar.

---

<div class="post-metadata">

**Author:** ![stefan](https://avatars.discourse-cdn.com/v4/letter/s/bbce88/32.png) [@stefan](https://community.weweb.io/u/stefan)\
**Post date:** [July 19, 2024, 1:59pm UTC](https://community.weweb.io/t/how-can-i-receive-the-current-and-published-weweb-live-version-with-javascript/9720/12 "2024-07-19T13:59:50Z")

</div>

Hi there,

I am currently using this code, but the message box (set by a variable) is always on top. When I click the refresh button in my message box, the **message box still keeps showing**. Each refresh the code think there is a new version. Does anyone have any suggestions on what might be causing this issue and how to solve this problem?

My code, in the app load event:

```auto
if('serviceWorker' in navigator){
  navigator.serviceWorker.register('/serviceworker.js').then((registration) => {
    console.log('Service Worker registered with scope:', registration.scope);

    // Check for updates
    registration.onupdatefound = () => {
      const installingWorker = registration.installing;
      installingWorker.onstatechange = () => {
        if(installingWorker.state === 'installed'){
          if(navigator.serviceWorker.controller){
            // New update available
            notifyUserAboutUpdate();
          }
        }
      };
    };
  }).catch((error) => {
    console.error('Service Worker registration failed:', error);
  });
}

function notifyUserAboutUpdate(){
// variable AppUpdateAvailable (boolean)
variables['90b9e60d-521f-40fa-8514-287c0e724eac'] = true;
// window.location.reload();
}

```

Thanks,  
Stefan

---

<div class="post-metadata">

**Author:** ![stefan](https://avatars.discourse-cdn.com/v4/letter/s/bbce88/32.png) [@stefan](https://community.weweb.io/u/stefan)\
**Post date:** [August 9, 2024, 11:18am UTC](https://community.weweb.io/t/how-can-i-receive-the-current-and-published-weweb-live-version-with-javascript/9720/13 "2024-08-09T11:18:31Z")

</div>

Hi there,

Does anyone have another working solution that matches the limitations of the weweb platform?

Thanks,  
Stefan
