开发者

Loading page while rails app starts?

开发者 https://www.devze.com 2023-01-09 21:40 出处:网络
I have a rails application on a shared server that also has a decently sized database, which is still growing, behind it. The application takes a long 开发者_高级运维time to start/load the homepage, a

I have a rails application on a shared server that also has a decently sized database, which is still growing, behind it. The application takes a long 开发者_高级运维time to start/load the homepage, about 20-30 seconds for me, although some people report waiting up to several minutes.

Is there a way to flash a notice that informs people that the database may take several minutes to load while they are waiting?


It's hard to say based on your question, since we don't know exactly what your home page is showing or how it's displaying it, but assuming you are referring to an AJAX (based on the tag) call that is retrieving something from the database to be displayed on your homepage, there are a few things you can try:

  1. Paginate the items. Is whatever you're loading a long list of items? If so, only retrieve a few at once, and let the user decide if they want to see more.

  2. Load the rest of the page (header, footer, navigation bar, etc), and then place a loading gif spinner in the area where the content is to be loaded. If you use a javascript library like jQuery this is pretty trivial, and there are a ton of tutorials out there for it. Here is a good site for free loading indicators: http://ajaxload.info/. What you'll want to do is make the AJAX call and use your javascript library to set the loading image. Then, in the success callback for your ajax call, hide the spinner and show the content.

  3. Load one item at a time. Make a separate ajax call for each item you're going to load, so that the user sees them coming in. This will probably end up taking longer overall (you're hitting the database more often), but the visual may be a nice psychological hack.

  4. Look at how your database queries are set up. Are you getting everything you need in one find? That's the best way to do it, as every time you have to make another trip to the database you're increasing the wait time.

Other than that the best thing you can do is get better hardware if possible, maybe look into a VPS like linode.com.

0

精彩评论

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