plus_plugins icon indicating copy to clipboard operation
plus_plugins copied to clipboard

feat(package_info_plus): implemented version caching based on serviceworkerversion

Open ikbendewilliam opened this issue 7 months ago • 1 comments

Description

Instead of always fetching the latest version on web (because of a cachebuster), we will possibly retrieve the cached version depending on the serviceWorkerVersion from index.html. This is an opt in as you will need to add one line to your index.html and otherwise falls back to the current way of working (cachebuster).

This will result in a more robust version retrieval as the cache will only be used if the index.html file is cached. If the index.html file is a newer version, we will also retrieve the newer build version.

  <script>
    // The value below is injected by flutter build, do not touch.
    const serviceWorkerVersion = null;
    window.serviceWorkerVersion = serviceWorkerVersion; // <-- Adding this line in your index.html will enable this behaviour
  </script>

Related Issues

  • Fix #2675

Checklist

  • [x] I read the Contributor Guide and followed the process outlined there for submitting PRs.
  • [x] I titled the PR using Conventional Commits.
  • [x] I did not modify the CHANGELOG.md nor the plugin version in pubspec.yaml files.
  • [x] All existing and new tests are passing.
  • [x] The analyzer (flutter analyze) does not report any problems on my PR.

Breaking Change

  • [x] No, this is not a breaking change.

ikbendewilliam avatar Apr 18 '25 14:04 ikbendewilliam

For Flutter 3.29, the serviceworkerversion variable is no longer directly accessible in javascript, but the only change is to add a small js script in the index.html instead. See https://github.com/ikbendewilliam/plus_plugins/blob/feat/flutter-3.29/packages/package_info_plus/package_info_plus/example/web/index.html and https://github.com/ikbendewilliam/plus_plugins/blob/feat/flutter-3.29/packages/package_info_plus/package_info_plus/example/web/service_worker_version_reader.js

ikbendewilliam avatar Apr 25 '25 14:04 ikbendewilliam