jQuery - 改进性能/代码 [英] jQuery - Improving Performance / Code

查看:88
本文介绍了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)

jQuery性能规则主题包括:



  1. 始终从#id下降

  2. 在课前使用标签

  3. 缓存jQuery对象

  4. 利用链接的力量

  5. 使用子查询

  6. 限制直接DOM操作

  7. 利用事件委派(又名冒泡)

  8. 消除查询浪费

  9. 按照$(窗口).load

  10. 压缩你的JS

  11. 学习图书馆

  1. Always Descend From an #id
  2. Use Tags Before Classes
  3. Cache jQuery Objects
  4. Harness the Power of Chaining
  5. Use Sub-queries
  6. Limit Direct DOM Manipulation
  7. Leverage Event Delegation (a.k.a. Bubbling)
  8. Eliminate Query Waste
  9. Defer to $(window).load
  10. Compress Your JS
  11. Learn the Library


jQuery性能和优化技巧主题包括:



  1. 保持最新!您使用过时的方法和技术吗?。

  2. 上下文感知jQuery代码执行 - 您是否正在加载不需要的代码?

  3. jQuery单元测试

  4. 基准测试jQuery代码

  5. 使用一个压缩的主JS文件将下载时间保持在最低限度。

  6. 上下文与查找

  7. 一直到Window.load。

  8. 在您使用JavaScript和&之间取得平衡jQuery

  1. Stay up to date! Are you using methods and techniques that are obsolete?.
  2. Context-aware jQuery Code Execution – Are you loading code that isn’t needed?
  3. jQuery Unit Testing
  4. Benchmark Your jQuery Code
  5. Keep download times to a minimum with one compressed master JS file.
  6. Context Vs. Find
  7. Window.load all the way.
  8. Strike A Balance Between Your Use Of JavaScript & jQuery


jQuery Performance Tuning Tips - Paul Irish 主题包括:



  1. 优化Sizzle从右到左模式的选择器

  2. 使用live()而非点击()

  3. 拉使用它们时DOM的元素

  4. 使用find()而不是上下文

  5. 使用HTML 5

  6. 在样式化15个或更多元素时附加样式标记

  7. 使用Google Page Speed测试选择器

  8. 即使jQuery没有抛出,也使用对象检测错误

  9. 使用直接功能而非便利功能

  10. 了解鲜为人知的方法

  1. Optimize selectors for Sizzle’s ‘right to left’ model
  2. Use live() not click()
  3. Pull elements off of the DOM while you play with them
  4. Use find() rather than context
  5. Use HTML 5
  6. Append style tags when styling 15 or more elements
  7. Test selectors using Google Page Speed
  8. Use object detection even if jQuery doesn't throw an error
  9. Use direct functions rather than their convenience counterparts
  10. Learn the lesser known methods


改进jQuery Per大数据集的形成主题包括:



  1. 使用JavaScript native for()循环而不是jQuery的$ .each()帮助器

    函数。

  2. 不要在循环中向DOM附加元素。

  3. 如果要将大量元素插入到DOM中,请使用父元素包围它们
    以获得更好的
    性能。

  4. 不要使用字符串连接,而是使用数组的join()方法为
    一个非常长的字符串。

  5. 使用setTimeout()函数进行长列表循环和连接

    函数。

  1. Use JavaScript native for() loop instead of jQuery's $.each() helper
    function.
  2. Do NOT append an element to the DOM in your loop.
  3. If you have a lot of elements to be inserted into the DOM, surround them
    with a parent element for better performance.
  4. Don't use string concatenation, instead use array's join() method for a very long strings.
  5. 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 - 改进性能/代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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