开发者

Good or bad idea : load database as a separate .js file

I have a web page where you can customize your game character. In order to speed up browsing (gems) I load entire gems database (600 entries, 247KB) as a separate .js file, so it can be cached and I don't need to load it every time.

I don't notice a delay, is it still a bad idea?

Should I ajax-get necessary records on the fly instead?

FYI: I use ASP.NET MVC 2.0, here is loading the script:

<script type="text/javascript" src='./Data.aspx/Gems'></script>

And here is the action:

[OutputCache(Duration = 14400, VaryByParam = null)]
public ActionResult Gems() {...}

EDIT: My main concern is not load time, but memory usage.开发者_如何学Go Is it going to have noticeable impact having excra 250KB of javascript loaded/parsed by browser?


I find it a pretty good idea. Plus, if you ever need to "upgrade" the GEMS database you can just load up the scripts with a version tag like

 <script type="text/javascript" src='./Data.aspx/Gems?v=1232'></script>

Where v=123 will force the user to download the new version if required.


I assume the page won't function until the script is fully loaded anyway but to make the page feel faster you should load the javascript at the bottom of the page.


Embedding the data as a script will cause the browser to halt page loading until the script file has been downloaded and parsed.

If you fetch a static script or data file using ajax, the browser should cache it as if it was an inline script, so there isn't any downside to using ajax, and you don't have to worry about slowing the page load.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜