# Local and PWA guide — Session 6

> The goal is a small test with fictional data. This material does not automatically turn an Apps Script app into an offline app. Define the required features first and keep the original.

## 1. Three meanings of “local”

| Situation | What changes | What it does not imply |
|---|---|---|
| Editor on your computer | The workshop instead of a Codespace | The app may still need Google and a network |
| HTML with browser-stored data | The pilot’s logic and saving | No shared spreadsheet or automatic synchronisation |
| PWA | Manifest, installation and intended cached resources | Installation does not guarantee every feature offline |

`google.script.run` connects the frontend to Apps Script. Opening its HTML outside that environment does not run the backend. Explicitly adapt logic and saving; copying Index.html alone does not complete the conversion.

## 2. A stable test origin

On `file://` URLs, localStorage persistence has no guaranteed behaviour across browsers. If testing with a double click, check closing, reopening, moving or renaming the file. Do not treat it as the only copy of important data. [MDN: localStorage](https://developer.mozilla.org/en-US/docs/Web/API/Window/localStorage).

For repeatable tests, serve a practice folder at a fixed address and port. If **Python is already available**, open a terminal inside that folder and run:

```sh
python -m http.server 8787 --bind 127.0.0.1
```

Open `http://127.0.0.1:8787/` and stop the server with Ctrl+C afterwards. The folder must contain only the pilot and fictional data: do not serve your personal folder or a repo containing credentials. If the port is occupied, identify the process or choose another port; changing ports also changes the data origin. Do not blindly stop other services or install tools just to follow the example: ask for an alternative compatible with your environment.

Protocol, host and port are part of the origin. `localhost`, `127.0.0.1`, HTTP and HTTPS do not necessarily share storage. Each profile and device has its own storage. Private browsing or restrictions may prevent persistence.

## 3. Save and recover

localStorage may suffice for a small pilot; larger or structured data may require IndexedDB or another design. Choose according to volume and operations, rather than the tool’s name.

- Define a dedicated key and schema version. Do not overwrite data you do not understand.
- Catch read, quota and write errors. Show a useful error; never report “saved” after failure.
- Export a JSON backup with version and data. A CSV report does not replace a backup preserving structure.
- Restore first in a separate profile or environment. Validate structure, types, size and limits, show a preview and request confirmation before replacing data.
- Reject invalid backups without changing existing data. Render user input as text, rather than HTML code.

The course portfolio stores context and progress, rather than records from the app you built. A progress backup does not automatically recover your pilot’s data.

## 4. Prepare a PWA

Prepare and test a PWA at a compatible origin, usually HTTPS or localhost. Double-clicking a file is not the service worker test route. The browser and system determine which installation options are offered. [MDN: installation](https://developer.mozilla.org/en-US/docs/Web/Progressive_web_apps/Guides/Making_PWAs_installable).

The manifest describes name, identifier, start, scope, display and icons. A service worker can manage cached resources. For a project published under `/REPO/`, check relative paths, start_url, scope and worker registration inside that folder. [MDN: service workers](https://developer.mozilla.org/en-US/docs/Web/API/Service_Worker_API/Using_Service_Workers).

Plan what to cache: HTML, CSS, JavaScript, icons and other required static resources, without mandatory remote fonts. Do not indiscriminately cache authenticated responses, secrets or writes. Provide an understandable response when a resource is missing. Use a dedicated cache name; do not delete other projects’ caches on the same domain.

After an initial online load and worker control, disconnect, reload and test. Google services, remote login and cloud databases do not become available offline because an icon has been installed. Shared data and offline use require queues, synchronisation and conflicts to be designed as a specific project.

## 5. Updates and publishing

Version cached resources, but retain the data key and schema. Notify users when an update is ready without forcing a reload that loses text being edited. Export before schema changes and test v1→v2 with practice data. The file cache is not a data backup.

GitHub Pages is static hosting and **is not** the S5 Apps Script deployment. Check the plan and configuration before publishing: repo privacy and website access are separate decisions. Browser-served resources can be inspected. Keep secrets and restricted data out. [GitHub Pages](https://docs.github.com/en/pages/getting-started-with-github-pages/about-github-pages).

Pages has usage limits and terms; it is not a general hosting proposal for any business or commercial SaaS. For business use, compare suitable hosting and required access before publishing. [Pages limits](https://docs.github.com/en/pages/getting-started-with-github-pages/github-pages-limits).

## 6. Public configuration and secrets

Platforms design some configuration values for the client. This does not authorise access to all data. In Supabase, for example, distinguish publishable and secret keys, and check RLS policies. Never send a privileged key or password to the browser. An environment variable bundled into the frontend may also be visible. [Supabase keys](https://supabase.com/docs/guides/api/api-keys) · [RLS](https://supabase.com/docs/guides/database/postgres/row-level-security).

## 7. Evidence before saying “it works”

Complete the [S6 worksheet](fitxa-proves-s6.md): valid and invalid cases, access, closing/reopening, save errors, backup and restore, offline reload, missing resources and updates without data loss. Record browser, device, origin, version, steps and results. Distinguish proposed, simulated and executed tests. Compatibility in one browser does not prove every device.

Reviewed on 2026-10-26. Verify installation options, plans and policies when carrying out the exercise.
