zhartaunik-fork/magento2-serviceworker
Composer 安装命令:
composer require zhartaunik-fork/magento2-serviceworker
包简介
A Magento 2 extension that adds Service Worker support.
README 文档
README
A Magento 2 extension that adds Service Worker support.
Features:
- Fully customisable Service Worker script
- Cache-first approach for page assets resulting in faster page loads
- Offline cache for CMS and catalog pages allowing viewing previously visited pages while in poor network conditions
Installation
Add this extension to your Magento installation with Composer:
composer require meanbee/magento2-serviceworker
Usage
Configuration
The Service Worker is configured and enabled by default. However, Service Workers require the site to run on HTTPS.
Features can be customised in Stores > Configuration > General > Web > Service Worker Settings.
Adding more logic
If the base service worker file doesn't fit all of your needs you can easily add more logic using the layout system, targeting the serviceworker_index_js handle:
<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<body>
<referenceBlock name="serviceworker">
<block class="\Meanbee\MoreLogic\Block\Logic" name="morelogic.logic" template="Meanbee_MoreLogic::logic.phtml" />
</referenceBlock>
</body>
</page>
FAQ
Why do page assets not appear to be cached when Magento is in default/developer mode?
Magento 2 uses a timestamp version string in the URL for static files to allow busting browser cache when the static content gets updated. In developer mode, this version string is updated for every unique page request. This means that from the browser's perspective, the static assets, such as CSS files, are completely different on each page, even though the content is the same. Therefore, when the assets get cached by the Service Worker in Magento 2 developer mode, they only get cached for that specific page. Production mode only generates the static assets through command line and keeps the version timestamp fixed, so it doesn't experience this issue.
Development
Setting up a development environment
A Docker development environment is included with the project:
docker-compose run --rm cli magento-extension-installer Meanbee_ServiceWorker \
&& docker-compose up -d
npm dependencies
The extension uses npm to manage some of its web dependencies. Dependencies are installed and updated using npm, then
copied into the src/ directory using an npm script. To update the web dependencies, run:
docker-compose run --rm node npm update
docker-compose run --rm node npm run build
Testing Service Workers on Chrome
Chrome is very strict about security and only allows Service Workers on localhost, or on an HTTPS site with a valid certificate. To bypass these restrictions for testing, use the --ignore-certificate-errors and --unsafely-treat-insecure-origin-as-secure flags to run a less secure copy of Chrome:
/Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome \
--user-data-dir=/tmp/chrome \
--ignore-certificate-errors \
--unsafely-treat-insecure-origin-as-secure=https://m2-meanbee-serviceworker.docker/
zhartaunik-fork/magento2-serviceworker 适用场景与选型建议
zhartaunik-fork/magento2-serviceworker 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 6 次下载、GitHub Stars 达 0, 最近一次更新时间为 2022 年 07 月 13 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 zhartaunik-fork/magento2-serviceworker 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 zhartaunik-fork/magento2-serviceworker 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 6
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 17
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2022-07-13