好主意或坏主意:将数据库作为单独的 .js 文件加载

发布于 2024-09-30 04:50:17 字数 532 浏览 0 评论 0原文

我有一个网页,您可以在其中自定义您的游戏角色。为了加快浏览速度(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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

一百个冬季 2024-10-07 04:50:17

我觉得这是一个很好的主意。另外,如果您需要“升级”GEMS 数据库,您只需加载带有版本标记的脚本即可,

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

其中 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

 <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.

夜司空 2024-10-07 04:50:17

我认为无论如何,在脚本完全加载之前页面都不会起作用,但为了使页面感觉更快,您应该 在页面底部加载 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.

花想c 2024-10-07 04:50:17

将数据嵌入为脚本将导致浏览器停止页面加载,直到下载并解析脚本文件。

如果您使用 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文