移动网络应用性能问题

发布于 2024-12-03 08:07:24 字数 1639 浏览 0 评论 0原文

我正在构建一个移动 Web 应用程序,尽管我仍处于原型设计过程中,但我很难修复某些性能问题。

应用程序本身(在桌面浏览器中运行一切顺利,但在移动 Safari 中运行明显缓慢): Hancards webapp 原型。您可以使用mifeng:wangwang登录或创建一个新用户。

不过,整体笨拙的性能是可以容忍的,除了一件事:当您打开设置的页面,点击“查看”(放大所有卡片)然后尝试返回到上一页时,浏览器会崩溃(!)。

steps

点击“view”时执行的代码是这样的(本身也非常缓慢;任何改进的方法它?):

if ($(this).hasClass('big')) {
    $('.card').unwrap().removeClass('big flippable').addClass('small');
    $(this).removeClass('big');
}
else {
    $('.card').wrap('<div class="bigCardWrap" />').removeClass('small').addClass('big flippable');
    $(this).addClass('big');
}

还有一件事,一个非常奇怪的错误。很多时候,“每日一词”块不会显示最后一个元素的文本节点 (

),即使它在代码中也是如此。无论如何,除非您“摇动”DOM,否则文本不会显示(取消勾选并重新勾选关联的 CSS 属性之一也可以实现这一点)。这种情况在桌面和移动 Safari 浏览器中都会发生。

在那里写入的代码是这样的:

// While we are here, also display the Word of the day
$.post('ajax.php', {action: 'stuff:showWotd'}, function(data) {

    // Decode the received data
    var msg = decodeResponse(data);

    // Insert the values
    $('.wotd .hanzi').text(msg.content[0]['hanzi']);
    $('.wotd .pinyin').text(msg.content[0]['pinyin']);
    $('.wotd .meaning').text(msg.content[0]['meaning']);

});

mysterious text node

我不希望你建议我如何修复整个应用程序的性能(我可能必须修改项目的整体范围,而不是试图找到解决方法),但我至少想看看如何解决这两个问题。谢谢你!

I’m building a mobile web application, and even though I’m still in a prototyping kind of the process, I’m having a hard time fixing certain performance problems.

The application itself (works all smooth in desktop browsers, but significantly sluggish in Mobile Safari): Hancards webapp prototype. You may login as mifeng:wangwang or create a new user.

The overall clumsy performance could be tolerable though, except for one thing: the browser simply crashes (!) when you open a set page, tap ‘view’ (enlarge all cards) and then try to go back to the previous page.

steps

The code that gets executed when ‘view’ is tapped is this (very sluggish by itself as well; any way to improve it?):

if ($(this).hasClass('big')) {
    $('.card').unwrap().removeClass('big flippable').addClass('small');
    $(this).removeClass('big');
}
else {
    $('.card').wrap('<div class="bigCardWrap" />').removeClass('small').addClass('big flippable');
    $(this).addClass('big');
}

And another thing, a pretty weird bug. Very often the ‘word of the day‘ block won’t display the text node for the last element (<div class="meaning">), even though it’s in the code. The text will not show unless you ‘shake’ the DOM anyhow (unticking and ticking back one of the associated CSS properties can also achieve that). This happens in both desktop and mobile Safari browsers.

The code that writes it in there is this:

// While we are here, also display the Word of the day
$.post('ajax.php', {action: 'stuff:showWotd'}, function(data) {

    // Decode the received data
    var msg = decodeResponse(data);

    // Insert the values
    $('.wotd .hanzi').text(msg.content[0]['hanzi']);
    $('.wotd .pinyin').text(msg.content[0]['pinyin']);
    $('.wotd .meaning').text(msg.content[0]['meaning']);

});

mysterious text node

I don’t expect you to advice me on how to fix the performance of the whole application (I will probably have to revise the overall scope of the project instead of trying to find workarounds), but I at least would like to see how to solve these two problems. Thank you!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

套路撩心 2024-12-10 08:07:24

我在脚本中看到的唯一性能问题是包装/展开调用 - 从 DOM 添加和删除元素往往相当慢,并且您可以通过始终拥有包装器元素并更改其类而不是添加来获得相同的效果或将其删除。

但是,您看到的性能问题很可能出现在 css 中:

  • 由于硬件加速,3D 变换可能比 2D 快得多。看起来您已经有了这个,尽管您确实需要小心它应用于
  • 阴影的哪些元素存在真正的性能问题,尤其是在动画时。删除它们可能会解决大部分缓慢问题。
  • 重新排列背景图像会有所帮助 - 透明页面下的单个背景图像比每个页面都有一个背景图像更快。

The only performance issue I see in the script is the wrap/unwrap calls - adding and removing elements from the DOM tends to be fairly slow, and you can probably get the same effect by always having a wrapper element and changing its class rather than adding or removing it.

However, the performance issues you are seeing are most likely in your css:

  • 3D transforms can be much faster than 2D due to hardware acceleration. It looks like you already have this, though you do need to be careful about which elements it is applied to
  • Shadows have real performance issues, especially when animated. Removing them will probably fix most of the slowness.
  • Rearranging background images can help - A single background image under transparent pages is faster than having a background image for each page.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文