好主意或坏主意:将数据库作为单独的 .js 文件加载
我有一个网页,您可以在其中自定义您的游戏角色。为了加快浏览速度(gems),我将整个 gems 数据库(600 个条目,247KB)作为单独的 .js 文件加载,因此可以对其进行缓存,并且不需要每次都加载它。
我没有注意到延迟,这仍然是一个坏主意吗?
我应该用 ajax 动态获取必要的记录吗?
仅供参考:我使用 ASP.NET MVC 2.0,这里正在加载脚本:
<script type="text/javascript" src='./Data.aspx/Gems'></script>
这里是操作:
[OutputCache(Duration = 14400, VaryByParam = null)]
public ActionResult Gems() {...}
编辑: 我主要关心的不是加载时间,而是内存使用情况。浏览器加载/解析的额外 250KB 的 JavaScript 是否会产生明显的影响?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我觉得这是一个很好的主意。另外,如果您需要“升级”GEMS 数据库,您只需加载带有版本标记的脚本即可,
其中
v=123
将强制用户在需要时下载新版本。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
Where
v=123
will force the user to download the new version if required.我认为无论如何,在脚本完全加载之前页面都不会起作用,但为了使页面感觉更快,您应该 在页面底部加载 JavaScript。
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.
将数据嵌入为脚本将导致浏览器停止页面加载,直到下载并解析脚本文件。
如果您使用 ajax 获取静态脚本或数据文件,浏览器应该像内联脚本一样缓存它,因此使用 ajax 没有任何缺点,并且您不必担心页面加载速度变慢。
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.