本文介绍了jQuery - 改进性能/代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我刚刚开始使用jQuery,我一直在寻找一些关于如何提高代码速度/性能的资源。我想知道是否有人有任何可能帮助我的提示或资源。
I just started working with jQuery and I have been searching for some type of resource on how to improve the speed/performance of my code. I was wondering if anyone had any tips or resources that could possibly help me out.
谢谢,
Bev
推荐答案
我在这个主题上写了一些书签,希望他们会帮助你解决所需问题。 (主题范围从简单到高级)
I had a few sites bookmarked on this very topic, hopefully they will help you out with what you need. (Topics range from simple to advanced)
主题包括:
- 始终从#id下降
- 在课前使用标签
- 缓存jQuery对象
- 利用链接的力量
- 使用子查询
- 限制直接DOM操作
- 利用事件委派(又名冒泡)
- 消除查询浪费
- 按照$(窗口).load
- 压缩你的JS
- 学习图书馆
- Always Descend From an #id
- Use Tags Before Classes
- Cache jQuery Objects
- Harness the Power of Chaining
- Use Sub-queries
- Limit Direct DOM Manipulation
- Leverage Event Delegation (a.k.a. Bubbling)
- Eliminate Query Waste
- Defer to $(window).load
- Compress Your JS
- Learn the Library
主题包括:
- 保持最新!您使用过时的方法和技术吗?。
- 上下文感知jQuery代码执行 - 您是否正在加载不需要的代码?
- jQuery单元测试
- 基准测试jQuery代码
- 使用一个压缩的主JS文件将下载时间保持在最低限度。
- 上下文与查找
- 一直到Window.load。
- 在您使用JavaScript和&之间取得平衡jQuery
- Stay up to date! Are you using methods and techniques that are obsolete?.
- Context-aware jQuery Code Execution – Are you loading code that isn’t needed?
- jQuery Unit Testing
- Benchmark Your jQuery Code
- Keep download times to a minimum with one compressed master JS file.
- Context Vs. Find
- Window.load all the way.
- Strike A Balance Between Your Use Of JavaScript & jQuery
主题包括:
- 优化Sizzle从右到左模式的选择器
- 使用live()而非点击()
- 拉使用它们时DOM的元素
- 使用find()而不是上下文
- 使用HTML 5
- 在样式化15个或更多元素时附加样式标记
- 使用Google Page Speed测试选择器
- 即使jQuery没有抛出,也使用对象检测错误
- 使用直接功能而非便利功能
- 了解鲜为人知的方法
- Optimize selectors for Sizzle’s ‘right to left’ model
- Use live() not click()
- Pull elements off of the DOM while you play with them
- Use find() rather than context
- Use HTML 5
- Append style tags when styling 15 or more elements
- Test selectors using Google Page Speed
- Use object detection even if jQuery doesn't throw an error
- Use direct functions rather than their convenience counterparts
- Learn the lesser known methods
主题包括:
- 使用JavaScript native for()循环而不是jQuery的$ .each()帮助器
函数。 - 不要在循环中向DOM附加元素。
- 如果要将大量元素插入到DOM中,请使用父元素包围它们
以获得更好的
性能。 - 不要使用字符串连接,而是使用数组的join()方法为
一个非常长的字符串。 - 使用setTimeout()函数进行长列表循环和连接
函数。
- Use JavaScript native for() loop instead of jQuery's $.each() helper
function. - Do NOT append an element to the DOM in your loop.
- If you have a lot of elements to be inserted into the DOM, surround them
with a parent element for better performance. - Don't use string concatenation, instead use array's join() method for a very long strings.
- Use setTimeout() function for your long list looping and concatenation
functions.
希望这些足以让你开始踏上jQuery性能天堂之旅。
Hopefully these will be enough to get you started on your journey to jQuery performance heaven.
这篇关于jQuery - 改进性能/代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!