仅对整个网站使用AJAX,无论是否为最佳 [英] Using AJAX only for whole website,optimal or not

查看:121
本文介绍了仅对整个网站使用AJAX,无论是否为最佳的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个模板结构,其中有一个HTML文件,其中有相关的HTML& JS文件已加载(使用AJAX).

I am having a template structure in which there is a single HTML file inside which related HTML & JS files are loaded (using AJAX).

部分将根据用户的活动进行加载(页面从不重新加载哪种类型对用户体验有利). 即

Section are loaded as per User's activity(Page never reloads which kind of is good for user experience). i.e.

用户单击菜单配置文件",这将导致:

User clicks a menu say "Profile",which causes:

  1. jQuery.load 方法用于加载文件"/some/path/profile.html".

  1. jQuery.load method is used to load a file "/some/path/profile.html".

jQuery.getScript 用于 .load()回调,以包含js文件,例如"some/path/profile.js",配置文件js具有配置文件页面的事件处理程序以及相关的业务逻辑.

jQuery.getScript is used in .load() callback to include js files like "some/path/profile.js",The profile js has event handlers for the profile page along with related business logic.

对于应用程序的每个菜单项/部分,例如配置文件",文件",仪表板"等,都会发生这种情况.

This happens for each menu item/section of the application like "Profile","Files","Dashboard" etc.

它运行很快,但是我不确定这是否是实现此目标的最佳方法.

It works fast but I am not sure if this is the optimal way to carry this out.

  • 如果用户随后两次单击配置文件"按钮,浏览器是否会 首先先清除较早加载的资源(profile.html,profile.js) 重新加载吗?

  • If a User consequently clicks the "Profile" button twice,would the browser clear up the earlier loaded resources(profile.html,profile.js) first before loading it afresh?

当用户访问个人资料"后访问新部分时,说仪表板"时, 浏览器再次加载Profile的资源,然后再加载 仪表板?

When user visit a new section say "Dashboard" after visiting "Profile",would browser again clear out the resources of Profile before loading for Dashboard?

如果不是这样,是否可能导致浏览器出现一些与内存相关的问题?我对此进行了搜索,但未发现任何相关情况.

If not than could this cause some memory related issues with the browser?I searched about this but did not see any related scenarios.

P.S:在此结构中,通常会将一些HTML部分存储在JS变量中,以供进一步使用.我在SO某处读到,这样做是不好的做法,但我无法找到有关它的详细信息.如果开发人员精通&,我认为这不是-ve点.将HTML存储在JS变量中应该没有问题.

P.S: In this structure often some HTML part is stored in a JS variable to be used further. I read somewhere in SO that it is a bad practice to do so but I was not able to find details regarding it. I assume it should not be a -ve point if the developer is well versed & storing HTML in a JS variable should not be any problem.

推荐答案

这是我的理解:

  • 如果单击末尾的同一按钮,则必须确保不发送请求.
  • (忘记我们正在处理脚本/HTMl)图片中没有缓存
  • 清除资源吗?是的,如果在同一部分中出现,它将从DOM中删除.但是我想如果每个部分的内容都使用相同的占位符是很有必要的.
  • 如果您知道每次每个部分都会再次返回相同的模板,则可以像备忘录一样在客户端创建本地缓存,以查看模板是否已经存在.

希望这会有所帮助.

这篇关于仅对整个网站使用AJAX,无论是否为最佳的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆