php - Tinymce sink 元素减少页面加载时间
问题描述
对于博客文件,由 php foreach 循环创建的文章的所有评论都有各自的Reply
按钮,用于在文本区域中打开带有 tinymce 的模态对话框。注意,当有评论时,页面加载需要一些时间。当我查看浏览器检查器时,我看到最后 tiny 正在为每个 textarea 加载一个“sink”元素,就在关闭标签之前body
:
<div class="tox tox-silver-sink tox-tinymce-aux" style="position: relative;"></div>
<div class="tox tox-silver-sink tox-tinymce-aux" style="position: relative;"></div>
<div class="tox tox-silver-sink tox-tinymce-aux" style="position: relative;"></div>
<div class="tox tox-silver-sink tox-tinymce-aux" style="position: relative;"></div>
<div class="tox tox-silver-sink tox-tinymce-aux" style="position: relative;"></div>
....and so on...
这些 div 的加载需要一些时间,并且会降低页面加载的性能。我能做些什么来提高页面加载的性能吗?
解决方案
正如 KIKO 所说,您需要为所有评论提供一个单一的回复模式。由于您没有指定您使用的平台,因此这是一种通用方法。
每个回复按钮都应该有一个数据属性,其中包含您要回复的评论的 ID。例如
<button class="reply-button" data-comment-id="<?php echo $comment->id; ?>">Reply</button>
或者,data-comment-id
如果评论将附加到帖子中,则将该属性留空,而不是作为对其他评论的回复。
如果您在单个页面上显示多个博客文章并希望每个文章都有自己的回复按钮,只需添加 data 属性post-id
,如下所示:
<button class="reply-button" data-post-id="<?php echo $blog_post->id; ?>">Reply</button>
使用 JavaScript 打开评论模式并选择适当的数据属性。例如:
$('.reply-button').on('click', function() {
const commentId = $(this).data('comment-id');
const postId = $(this).data('post-id');
showCommentModal(commentId, postId);
});
showCommentModal
功能应该显示您在页面上拥有的单一模式。使用commentId
它postId
应该准备发布评论作为对另一条评论或博客文章的回复。
推荐阅读
- javascript - 如何在vue中的另一个组件内以视觉方式显示数组中的值
- python - 如何在 Mac 上点安装 django-auth-ldap
- java - 如何使用 CSVWriter 仅在 csv 中嵌入的逗号字符串上使用双引号?
- javascript - 带有 React Nextjs 的粘性导航栏
- c# - jQuery Array 未发布到 ASP.NET MVC 控制器
- javascript - 如何使一个复选框控制其他复选框,并且每个复选框都有自己的设置来控制
- c# - 使用 SSIS 脚本任务摆脱存储为文本的数字
- node.js - 是否可以使用 pg-promise 在一次往返中获得 2 个查询的结果?
- javascript - 未捕获的语法错误:无法在模块外使用 import 语句
- bitbucket-pipelines - 使用来自 Bitbucket Pipelines 的 docker-maven-plugin 将图像推送到 DockerHub