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

浅谈RequireJs #10

Open
Roe-Tian opened this issue Oct 21, 2019 · 0 comments
Open

浅谈RequireJs #10

Roe-Tian opened this issue Oct 21, 2019 · 0 comments

Comments

@Roe-Tian
Copy link
Owner

Roe-Tian commented Oct 21, 2019

前言

在 ES6 出现之前,JS 不像其他语言同样拥有“模块”这一概念,于是为了支持 JS 模块化,出现了各种各样的语言工具,如 webpack,如 ReuqireJS。

正文

什么是 RequireJS

RequireJS 是一个 JavaScript 模块加载器。

使用 RequireJS 的好处

  • 模块化:模块化就是将不同功能的函数封装起来,并提供使用接口,他们彼此之间互不影响。
  • 不会阻塞页面:RequireJS,会在相关的 js 加载后执行回调函数,这个过程是异步的,所以它不会阻塞页面。
  • 按需加载:平时我们写 html 文件的时候,在底部可能会引用一堆 js 文件。在页面加载的时候,这些 js 也会全部加载。使用 require.js 就能避免此问题。举个例子,比如说我写了一个点击事件,放到了一个 js 文件里,并在 html 引用,在不使用 require.js 的情况下,页面加载它跟着加载,使用后则是什么时候触发点击事件,什么时候才会加载 js。

如何使用 RequireJS

未完待续

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

1 participant