Ext js 编码标准/最佳实践
谁能分享 ext js 编码标准吗?拥有两个版本的 js 文件是否值得——一个用于开发,另一个用于生产环境的压缩版本?
也有人可以建议一下我们可以拥有的 JS 文件的数量。我读到了一些 js 文件被串行下载的地方,因此避免仅仅为了可读性而添加新文件。而是将内容包含在最少数量的文件中。这是真的吗?
Can anyone share ext js coding standards? Is it worth enough to have two versions of js files - one during development and another compressed version for production environment?
Also can any one suggest on the number of JS files we can have. I read some where that js files gets downloaded serially and hence avoid adding new files just for the sake of readability. Rather to have the contents in minimal number of files. Is this true ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
还可以尝试构建 ext-all.js 的自定义版本。它通过减小文件大小节省了大量下载时间。我确信您不会在您的页面中使用整个文件。
我还建议您实现 prime cahce 概念,以便所有 JS/CSS 文件都在登录页面本身下载。这将使剩余页面加载速度更快。
对于您有关串行下载的问题,是的。每个js下载都是一个HTTP请求,并且是串行发生的。因此,如果页面加载时不需要,请尝试将 JS 文件下载到正文中。
Also try building the custom version for ext-all.js. It saves a lot of download time by reducing the file size. I am sure you wont be using the entire file for your page.
I would also suggest you to implement prime cahce concept so that all the JS/CSS files are downloaded on login page itself. This will make the remaining pages to load faster.
And for your question on serial download, Yes. Each js download is a HTTP request and it happens serially. So try to have JS files downloaded in the body, if it is not really required on page load.
是的..你应该有2个版本的JS..一个是应该在开发期间使用的调试版本,另一个是应该用于生产环境的文件的缩小版本。
应该使用缩小版本的原因是缩小版本的文件大小比调试版本小得多,因此在客户端下载速度更快。也尝试混淆......这进一步减小了大小,但有时可能会引入一些错误,因为混淆很难实现。 YUI 压缩机在这方面做得非常好。 JS 的大小越小,您的网站投入使用的速度就越快。
当您的 JS 包含在页面的
head
中时,它们会被串行下载。因此,为了避免这种情况,请将它们放在页面的body
部分中。这允许多个连接,因此您可以同时下载多个文件。请查看此页面了解更多此类提示。至于 ExtJ,请编写尽可能多的自定义组件。扩展内置类以满足您的需求。 Ext JS 包中包含多个示例,可供下载。如果您需要进一步帮助,请查看 extjs/example/ux 文件夹,了解随 Ext JS 发行版一起提供的 Ext JS 批准的自定义组件。
避免在组件中使用
id
。而是尝试使用itemId
或ref
来访问组件。Yes.. you should have 2 versions of your JS.. one is the debug version which should be used during development, and the minified version of the file which should be used for the production environment.
The reason why a minified version should be used is that file size of a minified version is much smaller than the debug version, hence gets downloaded faster at the client side. Try obfuscation too.. that reduces the size even further, but may sometimes introduce some errors, since obfuscation is pretty difficult to achieve. The YUI Compressor does a pretty good job of it. The smaller the size of your JSes, the faster your website will be ready for use.
When your JSes are included in the
head
of your page, then they are downloaded serially. So to avoid this, put them inside thebody
part of your page. That allows for multiple connections, hence you can download several files simultaneously. Check out this page for more such tips.As for ExtJs, write as many custom components as you can. Extend the built in classes to suit your needs. There are several examples included in the Ext JS package that is available for download. If you need further help, check out the extjs/example/ux folder for Ext JS approved custom components that are shipped along with the Ext JS distribution.
Avoid using
id
's in your components.. instead try usingitemId
orref
for accessing the components.看看复杂的官方例子的架构。
最好的方法——基于内置组件自己编写。
对于 ExtJS4,新的 MVC 架构在官方 API 文档中有很好的描述。
.js 的两个版本(调试版和生产版)应该可供任何选择。
Look at the architecture of complex official examples.
The best way - to write their own components based on the built-in.
For ExtJS4 new MVC architecture is well described in the official API-docs.
Two versions of .js (debug and production) should be for any choice.
鉴于您正在询问有关 Ext JS 3 的所有问题,我强烈建议切换到 Ext JS 4,其中组合和压缩所有 JavaScript 文件将变得更加容易,因为有一个特殊的工具。鉴于您现在问这个问题,不可能有太多的 JavaScript 文件需要转换。
Given that you are asking all this about Ext JS 3, I strongly suggest switching to Ext JS 4 where combining and compressing all your JavaScript files will be a whole lot easier, as there is a special tool for it. Given that you are asking this now, there can't be too many JavaScript files to convert over.