te')); return $arr; } /* 遍历用户所有主题 * @param $uid 用户ID * @param int $page 页数 * @param int $pagesize 每页记录条数 * @param bool $desc 排序方式 TRUE降序 FALSE升序 * @param string $key 返回的数组用那一列的值作为 key * @param array $col 查询哪些列 */ function thread_tid_find_by_uid($uid, $page = 1, $pagesize = 1000, $desc = TRUE, $key = 'tid', $col = array()) { if (empty($uid)) return array(); $orderby = TRUE == $desc ? -1 : 1; $arr = thread_tid__find($cond = array('uid' => $uid), array('tid' => $orderby), $page, $pagesize, $key, $col); return $arr; } // 遍历栏目下tid 支持数组 $fid = array(1,2,3) function thread_tid_find_by_fid($fid, $page = 1, $pagesize = 1000, $desc = TRUE) { if (empty($fid)) return array(); $orderby = TRUE == $desc ? -1 : 1; $arr = thread_tid__find($cond = array('fid' => $fid), array('tid' => $orderby), $page, $pagesize, 'tid', array('tid', 'verify_date')); return $arr; } function thread_tid_delete($tid) { if (empty($tid)) return FALSE; $r = thread_tid__delete(array('tid' => $tid)); return $r; } function thread_tid_count() { $n = thread_tid__count(); return $n; } // 统计用户主题数 大数量下严谨使用非主键统计 function thread_uid_count($uid) { $n = thread_tid__count(array('uid' => $uid)); return $n; } // 统计栏目主题数 大数量下严谨使用非主键统计 function thread_fid_count($fid) { $n = thread_tid__count(array('fid' => $fid)); return $n; } ?>javascript - jQuery - Improving PerformanceCode - Stack Overflow
最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - jQuery - Improving PerformanceCode - Stack Overflow

programmeradmin2浏览0评论

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.

Thanks,

Bev

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.

Thanks,

Bev

Share Improve this question asked Jan 15, 2011 at 14:28 WebDevBevWebDevBev 531 silver badge3 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 19

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 Performance Rules topics include :

  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 Performance and Optimization Tips topics include :

  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 pressed 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 topics include :

  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

Improving jQuery Performance with Large Data Sets topics include :

  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.

Hopefully these will be enough to get you started on your journey to jQuery performance heaven.

发布评论

评论列表(0)

  1. 暂无评论