Skip to content

[esnext] “所有import语句写在模块开始处”的说明是错误的 #21

Closed
@hax

Description

@hax

“import会被默认提升至模块最前面”这个说法是错误的,实际并不会。

“浏览器如能尽早读取相关的import内容则有可能更早地请求相关的依赖模块,有一定的性能提升作用,在HTTP/2之后可能会具有更明显的效果。”——这些说法也存疑,虽然理论上似乎是可能的。实际上更可能的是服务器端利用HTTP/2在没有请求的情况下预先发出被依赖的module——然而此种优化与import的前后并无关系。

另外bad的代码本身是错误的,import语句只能在top-level,而不能在函数里。

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions