Skip to content
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

[Feature Request] hash:true 可以不对模块联邦的构建产物生效 #11711

Closed
consistent-k opened this issue Oct 9, 2023 · 4 comments

Comments

@consistent-k
Copy link
Contributor

consistent-k commented Oct 9, 2023

1、项目为了避免缓存需要开启hash:true;
2、最近需要将项目内的部分组件进行共享给其他工程,使用模块联邦配置;
3、之后发现构建产物里remote.js 也会被加hash后缀,这样其他工程就无法固定remote的地址了;
需求:修改hash: true的生效范围不对mf的产物生效

image
@fz6m
Copy link
Member

fz6m commented Oct 9, 2023

没有 hash 的危害

如果名字没有 hash 就使得你需要对这个 remote.js 文件配置单独的 nginx 或者网关或者 CDN 响应头,标识它为无缓存的,这就导致用户每次都要全量下载这个 remote.js ,假如有很多应用,你要配置无数多次响应头配置到各个应用,并且每次打开网页都要加载大量的无缓存 remote.js

为什么 hash 是友好的

目前市面上或者企业内 CDN 广泛默认的配置就是对 JS 文件有长期的缓存头,这就要求把 js 文件都带上 hash ,所以在 mf 的场景,所有的 remote.[hash].js 的地址 url 应该从统一的配置中心获取后来下发,每次构建后配置中心同步变更对应带 hash 值的 url ,否则使用该功能的用户大概率就会踩到 remote.js 有缓存不更新的坑,并且他们很有可能无法调整 网关、CDN、nginx 的响应情况或者很难调整,所以带 hash 是友好的。

目前考虑的改良方向

考虑到小范围场景的应用,确实有用户需要不带 hash 的 remote.js ,欢迎 PR 增加一个 mf.remoteHash 的选项来控制输出是否带 hash 。

@fz6m
Copy link
Member

fz6m commented Oct 11, 2023

补充风险

没有了 hash 的风险在于,如果一次初始加载和异步加载之间有一次发布的话,构建产物不是同一批的可能会有问题。(比如 module id 和实际 module 的对应关系是不同的; treeshake 导致一个模块内的代码也是不同的)

from @stormslowly #11714 (comment)

推荐的做法

推荐的做法 还是有一个配置中心,下发一个当前使用的 remote 的 url,这样产物始终用都是同一次构建的内容。

参考 : https://umijs.org/docs/max/mf#rawmfimport

stormslowly pushed a commit that referenced this issue Oct 11, 2023
* feat(mf): 新增remoteHash参数控制mf的产物是否启用hash(#11711)

* Update packages/plugins/src/mf.ts

Co-authored-by: 咲奈Sakina <59400654+fz6m@users.noreply.github.com>

* feat(mf): 新增remoteHash参数控制mf的产物是否启用hash(#11711)

* Update docs/docs/docs/max/mf.md

* Update docs/docs/docs/max/mf.md

* Update docs/docs/docs/max/mf.md

---------

Co-authored-by: 咲奈Sakina <59400654+fz6m@users.noreply.github.com>
@fz6m fz6m closed this as completed Oct 12, 2023
@zch-123456
Copy link

zch-123456 commented Mar 9, 2024

参考https://umijs.org/docs/max/mf#rawmfimport 这个之后,每次的url也都是写死的,我在加载的js后面加上?t=Date.now(),之后发现,remote.js会去加载路径下的别的资源,此时加载的资源路径就出了问题,有什么解决方法不

@jadestarzuo
Copy link

参考https://umijs.org/docs/max/mf#rawmfimport 这个之后,每次的url也都是写死的,我在加载的js后面加上?t=Date.now(),之后发现,remote.js会去加载路径下的别的资源,此时加载的资源路径就出了问题,有什么解决方法不

我也是,同问

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

No branches or pull requests

4 participants