开发者

Using Ajax to Make Rails Website Faster

开发者 https://www.devze.com 2023-02-03 12:55 出处:网络
i\'m creating a website and i\'m thinking of ways to make it load as fast as possible. My website, as it happens with most, has a layout that is the same for every page. For instance, the header, the

i'm creating a website and i'm thinking of ways to make it load as fast as possible. My website, as it happens with most, has a layout that is the same for every page. For instance, the header, the external divs and so on are defined once in a layout and used likewise for every page that loads. The menu is always on the leftest div and never changes, and so on.

So, think of 5 areas. Top, left, center, right and footer. In my case, only the center has to change, depending on the page that i want to load. Therefore, i was thinking that using Ajax to do that would make loading way faster, since all other elements would already be loaded, right ?

So, i would like to ask whether there is a good resource or online tutorial that discusses this matter, as i would like to take a close look.

Thank you for re开发者_StackOverflowading that :)


Regarding @apneadiving's comment on caching the parts of the app, you'd use the fragment caching to handle that. http://api.rubyonrails.org/classes/ActionController/Caching/Fragments.html

You can load contents of the "main" part of your page using the approach here (using jQuery) Replace HTML page with contents retrieved via AJAX

Unless you know that your site's performance is unacceptable and that ajax will fix an issue you should probably avoid complicating things by using ajax. Remember premature optimization is the root of all evil :)


I'd advise you to avoid RJS because it's server-side javascript.

Use regular Ajax calls with the JS framework you like. A good asset here: http://peepcode.com/products/jquery-ajax

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号