Reputation: 21740
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. Is it going to have noticeable impact having excra 250KB of javascript loaded/parsed by browser?
Upvotes: 1
Views: 443
Reputation: 12294
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.
Upvotes: 1
Reputation: 20878
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.
Upvotes: 0
Reputation: 25165
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.
Upvotes: 2