Skip to content

feat(package_info_plus): implemented version caching based on serviceworkerversion #3549

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

ikbendewilliam
Copy link

@ikbendewilliam ikbendewilliam commented Apr 18, 2025

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

Checklist

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

Breaking Change

  • No, this is not a breaking change.

@ikbendewilliam
Copy link
Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Bug]: [package_info_plus] Web: Version info returns next version in server
1 participant