Updates from: 03/28/2023 01:31:34
Service Microsoft Docs article Related commit history on GitHub Change details
platform App Caching For Your Tab App https://github.com/MicrosoftDocs/msteams-docs/commits/main/msteams-platform/apps-in-teams-meetings/app-caching-for-your-tab-app.md
To enable app caching for your app, follow the steps:
* Dispose resources and perform any cleanup needed in the `beforeUnload` handler. * Invoke the `readyToUnload` callback to notify Teams client that the app unload flow is complete.
+# [TeamsJS v2](#tab/teamsjs-v2)
+
+[Sample code reference](https://github.com/OfficeDev/Microsoft-Teams-Samples/blob/main/samples/app-cache-meetings/nodejs/src/components/app-cache-tab.tsx#L73)
+ The following code snippet is an example of the `teamsCore.registerBeforeUnloadHandler` and `teamsCore.registerOnLoadHandler` handlers: ```javascript
-microsoftTeams.teamsCore.registerBeforeUnloadHandler((readyToUnload: any) => {
- const result = beforeUnloadHandler(setItems, readyToUnload);
- return result;
- });
+microsoftTeams.teamsCore.registerBeforeUnloadHandler((readyToUnload) => {
+ console.log("got beforeunload from TEAMS"); 
+ // dispose resources and then invoke readyToUnload
+ readyToUnload();
+ return true;
+});
+microsoftTeams.teamsCore.registerOnLoadHandler((data) => {
+ console.log("got load from TEAMS", data.contentUrl, data.entityId);
+ // use contentUrl to route to correct page
+ // invoke notifySuccess when ready
+ app.notifySuccess();
+});
+
+```
-microsoftTeams.teamsCore.registerOnLoadHandler((data: any) => {
- loadHandler(setItems, data);
- setTitle("Entity Id : " + data.entityId);
- console.log(data.contentUrl, data.entityId);
- });
+# [TeamsJS v1](#tab/teamsjs-v1)
+
+The following code snippet is an example of the `registerBeforeUnloadHandler` and `registerOnLoadHandler` handlers:
+
+```javascript
+microsoftTeams.registerBeforeUnloadHandler((readyToUnload) => { 
+ console.log("got beforeunload from TEAMS"); 
+ // dispose resources and then invoke readyToUnload 
+ readyToUnload(); 
+ return true; 
+});
+microsoftTeams.registerOnLoadHandler((data) => { 
+ console.log("got load from TEAMS", data.contentUrl, data.entityId); 
+ // use contentUrl to route to correct page 
+ // invoke notifySuccess when ready 
+ microsoftTeams.appInitialization.notifySuccess(); 
+}); 
```
-To view the complete code sample, see [app caching in meeting](https://github.com/OfficeDev/Microsoft-Teams-Samples/blob/main/samples/app-cache-meetings/nodejs/src/components/app-cache-tab.tsx#L73).
+ ## Best practices