使用 ajax 添加 TinyMCE 实例 - Grails
我有一个页面,用户可以添加 0 到 N 个 TinyMCE 编辑器,这些编辑器需要周围有一些 div 汤。
我在 gsp _template 中有 html 代码,因为它不止几行,而且我不想将其填充到 JavaScript 中。基本上每次用户单击“添加编辑器”时,都会以新 id 作为唯一参数对服务器进行 ajax 调用,控制器使用新 id 正确命名的元素呈现模板,并通过 javascript 将其附加到页面。
我认为这是一个非常优雅的解决方案,但令我困扰的是为每个要添加到页面的新编辑器触发的 ajax 调用,除了不同的元素 id 之外,该页面始终具有相同的代码。
这会对性能产生影响吗?第一次调用后模板是否被缓存? 谢谢
I have a page when user can add 0 to N TinyMCE editors that need to have some div soup around it.
I have the html code in a gsp _template because it is more then a few lines and I didn't want to stuff it in javascript. Basicaly everytime user clicks "add editor", an ajax call is made to the server with new id as the only parameter, controller renders the template with elements properly named using the new id, and it is appended by javascript to the page.
I think its a pretty elegant solution, but what bothers me are the ajax calls that are fired for every new editor that is to be added to the page which has always the same code apart from different element id's.
Will this have any performance impact? Is the template cached after first call?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
GSP 应该被编译(在 grails war 上预编译),然后有一些缓存来帮助加速 GSP 渲染。性能问题与考虑任何流量没有什么不同。服务器不关心(也不知道)该请求是 Ajax。它只是响应一个请求。如果您从等式中删除 ajax 并以这种方式看待它,您还会问性能问题吗?
也就是说,如果您需要的只是附加到模板中元素的 ID,我可能会研究类似 javascript 模板解决方案 (jquery.template() 例如)。这将完全否定对服务器的调用。
The GSP should be compiled (pre-compiled on grails war) and then there is some caching to help speed up GSP rendering. The performance issues are no different than considering any amount of traffic. The server doesn't care (or know) that the request is Ajax. It is just responding to a request. IF you remove ajax from your equation and just look at it that way, would you still be asking the performance question?
That said, if all you need is an ID attached to the elements in the template, I might look into something like a javascript template solution (jquery.template() for example). That would negate the call to the server entirely.