2009年10月21日 星期三

Choosing between an FBML or IFrame Application(1)

Choosing between an FBML or IFrame Application


Traditional IFrame Canvas Page


FBML Canvas Page



XFBML as part of Facebook Connect as a way to quickly get social content onto any Web page, and since IFrames are just Web pages, XFBML can speed those up as well.

Before XFBML, IFrame applications always had to make API calls to render social content like user names and profile pictures, and those API calls required another round trip communication between your server and Facebook before sending back content to the user's browser

with XFBML, you can embed various FBML tags like fb:name and fb:profile-pic directly into the HTML that your application sends to the user's browser. Then you simply include some Facebook-specific JavaScript, and that code gets executed and scans the DOM for those tags. The JavaScript then determines all the data needed to render that content and batches it up into one API call from the user's browser to Facebook

The rest of the page that isn't social content can render to the user before the API call completes. And in XFBML, we cache data on the browser so that in many cases, it isn't even necessary to make any API call to Facebook at all.

IFrame Canvas Page Using XFBML - First Page Load by a User


IFrame Canvas Page Using XFBML - Subsequent Page Loads by a User

2009年10月19日 星期一

找該加index 的地方

rails_indexes

check index exist

add_index 之前檢查一下

2009年10月18日 星期日

mustache 把view logic 的部份再拆出來

就是要讓view 更乾淨把logic 的部份再拆出來
mustache

Ruby on Rails Code Quality Checklist

Ruby on Rails Code Quality Checklist

1. Each controller action only calls one model method other than an initial find or new.
(Make custom .new or .update methods in the model with all necessary). ...
就是盡量把邏輯擺到model 裡, 唯一的例外就是在決定要render view or redirect的時候


2. Only one or two instance variables are shared between each controller and view. ...
保持一兩個instance variable 在controller 和 view 就好
這樣可以讓所有相關連的只有在需要的時候在被call 到, 而且還可以做instance-variable cache in one place
例如不要在controller 裡用到 @post and @related_posts 兩個instance variable, 而是create a method 給 @post, 這樣你就可以在 view 裡面直接用 @post.related_posts


3. All model and variable names are both immediately obvious (to a new developer) and as short as possible without using abbreviations. ...
取個好名字


4. All custom "finds" accessed from more than one place in the code use named_scope instead of a custom method. ...
有關find 什麼東西的, 都用named_scope 來做


5. A .find or .find_by_ is never called in a view or view helper. ...
別直接在view , find or find_by anything, 至少用一下namde_scope or custom methods to do that


6. There is zero custom code that duplicates functionality of a built-in function in rails. ...
7. Code has been aggressively DRYed during development. ...
8. All functionality used in two or more models has been turned into a library/module. ...
9. All logic duplicated between two or more apps has been turned into a gemified plugin. ...

10. STI is not used anywhere ...
別用STI, 用module 來代替, 如果你用STI 你會需要至少bind 兩個model, 這樣你很難回頭
data migration 你會死
但是polymorphic association 是鼓勵的


11. Every design choice should yield the most simplistic design possible for the need of users at the current time.
No guesses for future functionality were designed into the application. ...
對於現在的情況做最簡單的設計, 不要猜測未來的情況, 你可能會猜錯


12. Close to full test coverage exists at the highest level of the application: on and between controller actions. Coverage is highest for code used by the most number of end users. ...

先從user 最常用的開始測起
13. All tests pass before code is merged into a shared repository. ...

merge 前要測過
14. Every fixed defect on a deployed product has tests added to prevent regression. ...
替解掉的defeat 加上測試

15. Every plugin installed has been code reviewed. ...
檢查一下你的plugin code

Install any HTML theme/template into your Rails app

Install any HTML theme/template into your Rails app
install_theme
open source web design

幫你用來快速套template 的

2009年10月17日 星期六

[Scale] Scale Frontend 應該注意的五件事

[Scale] Scale Frontend 應該注意的五件事
Rails in the Wild: 5 Client-Side Performance Observations

1. It’s easy to forget to compress your JavaScript and CSS

要記得 :cache => true
要記得壓 js 和 css

2. Watch out for slow third party services

都是慢在第三方
google ads, analytics 也會托慢, 請用 postload_google_ads


3. Using multiple image hosts doesn’t always mean higher performance

拆那麼多台未必會比較快

4. S3 is NOT a Webserver!

S3 是 storage ,不是 web server。所以不要一股腦的把東西往上丟,要注意有沒有敏感資訊,而且 s3p 是沒有幫忙做 gzip 的。

5. Most performance variability is NOT attributable to page factors

速度慢通常是慢在後端..