当使用requireJS优化,什么是buildlayered的JavaScript的优势是什么? [英] When using the requireJS optimizer, what's the advantages of buildlayered javascript?

查看:264
本文介绍了当使用requireJS优化,什么是buildlayered的JavaScript的优势是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想我与 requireJs优化的第一次尝试 r.js(的这里),以prepare进行生产的申请。

I'm trying my first attempts with the requireJs optimizer r.js (here) to prepare an application for production.

我能得到的一切工作,并能丑化我所有的JS到一个单一的 main.js 文件,但是一个文件,很多问题...

I can get everything to work and can uglify all of my js into a single main.js file, but one file, many questions...

的基本问题


  1. 什么是JavaScript buildlayer requireJs在谈论?我的一个文件?

现在我只优化一个模块 main.js ,它捆绑了所有依赖到一个文件中(jQuery的,jQuery的移动,加上其他一切让我的应用程序所需的启动)。

Right now I only optimized one module main.js, which bundles all dependencies into a single file (jquery, jquery-mobile, plus everything else required to get my app started).

高级问题:结果
说一个页面我使用的是 jqplot 做了一个曲线图,它采用XY额外的JavaScript文件我不知道需要其他地方在我的应用程序。

Advanced questions:
Say on one page I'm using a graph done with jqplot, which uses xy additional javascript files I don't need anywhere else in my app.


  1. 我需要做什么来展示我的 main.built.js 文件多达做prevent这些文件?

  2. 请我需要定义一个新的模块我使用的图形,然后优化此模块XY文件Concat的到graph.built.js页面上的

  1. What do I need to do to prevent these files from showing up in my main.built.js file?
  2. Do I need to define a new module graph on the page I'm using the graph and then optimize this module to concat xy files into graph.built.js

非常先进:结果
我的页面是由小玩意=我敢重用整个应用程序和HTML / JS / CSS自主块可以使用JSON进行定制。

Very advanced:
My page is made of gadgets = autonomous blocks of HTML/JS/CSS which I'm reusing throughout the application and which can be customized using JSON.


  1. 如果通过 requireJS!文本插件,将在哪里我的HTML文件中优化大单的HTML文件?
  2. 装载小工具
  3. 如果我只想要加载,我需要每一页上,我必须创建每页一个模块依赖于每个小工具,然后优化模块index_page 的小工具, 模块page_with_graph 等,以确保只有什么需要被加载?

  4. 每一页VS缓存上
  5. 如果这样做,将重新请求小工具吗?

  1. If loading gadgets via the requireJS !text plugin, where will my HTML files be "optimized to" A large single HTML file?
  2. If I only want to load the gadgets I need on each page, do I have to create a module per page with dependencies for each gadget and then optimize module index_page, module page_with_graph, etc. to make sure only what's needed gets loaded?
  3. If doing so, will re-request gadgets on every page vs caching?

感谢射钉一些启发!

推荐答案

大guestions!

Great guestions!

基本问题:

什么是JavaScript buildlayer requireJs在谈论?我的
  单个文件?

What is the Javascript buildlayer requireJs is talking about? My single file?

Firstlly,让我们重新表述buildlayer为捆绑,它有更多的客观意义。因此,它串连模块设置。这可能是单一的 - 如果你把或者在一个构建或很少的模块,如果你想建立指定搭建一些网页

Firstlly, lets rephrase buildlayer as "bundle", it has more objective meaning. So its concatinated modules set. It could be single - if you put or your modules in one build or few if you would like to build specified build for some pages.

高级问题:

什么我需要做的prevent从显示这些文件我
  main.built.js文件?

What do I need to do to prevent these files from showing up in my main.built.js file?

首先,这里是一个非常有用的链接我有书签 - 的 https://github.com/jrburke/r.js/blob/master/build/example.build.js

First of all, here is a very usefull link i have in bookmarks - https://github.com/jrburke/r.js/blob/master/build/example.build.js

在几句话,您可以配置的模块部分的 r.js CONFIGS管理的包含 exlcude 规则要达到的目标。

In a few words you can configure modules section in r.js configs managing include and exlcude rules to reach the goal

我需要在网页上定义一个新的模块图我使用的图形
  然后优化此模块XY文件Concat的到graph.built.js

Do I need to define a new module graph on the page I'm using the graph and then optimize this module to concat xy files into graph.built.js

您可以只使用垫片并要求在对其他模块的需求。

You can just use shim and request in on demand on other modules

非常先进的:

如果通过requireJS!文本插件装载工具,其中,将我的HTML
  文件被优化大单的HTML文件?

If loading gadgets via the requireJS !text plugin, where will my HTML files be "optimized to" A large single HTML file?

不,它会在build.js。这样的结果,我不得不通过!文本中加载模板

Nope, it will be in build.js. This result i had loading templates via !text

如果我只想要加载,我需要在每个页面上的小工具,我必须
  每页创建一个模块依赖于每个小工具,然后
  优化模块index_page,模块page_with_graph等,以确保
  只有什么需要被加载?

If I only want to load the gadgets I need on each page, do I have to create a module per page with dependencies for each gadget and then optimize module index_page, module page_with_graph, etc. to make sure only what's needed gets loaded?

您可以建立每个页面的buldle,但这不是最好的主意。当我有类似的问题,我已经决定建立的,因为两个原因之一包 - 它装载的人,其更容易控制的CDN缓存,减少可能出现的错误和失误。但是如果你需要单独捆绑遵循张贴在模块部分的链接a've。

You can build own buldle for each page, but this is not the best idea. When i had similar question i've decided to build one bundle because of two reasons - it loads ones, its more easy to control cache on CDN and decrease possible errors and mistakes. But if you need separate bundles follow the link a've posted to the modules section.

如果这样做,将重新请求小工具在每一页上VS缓存

If doing so, will re-request gadgets on every page vs caching

所以,如果你加载页面,并有 DEP1 在10个模块的依赖文件将被加载一次(如果你没有它buld.js),然后在注射模块。当你重新加载页面文件可能来自浏览器缓存中获取或根据浏览器的配置再次加载。

So if you load the page and have dep1 in 10 modules dependencies file will be loaded once (if you dont have it in buld.js) and then injected in modules. When you reload the page file may be get from browser cache or loaded again according browser config.

希望这会有所帮助。

这篇关于当使用requireJS优化,什么是buildlayered的JavaScript的优势是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆