Using AJAX only for whole website,optimal or not

穿精又带淫゛_ 提交于 2019-12-12 01:19:20

问题


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 method is used to load a file "/some/path/profile.html".

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

  • 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?

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


回答1:


Here's my understanding on this:

  • You have to make sure that you don't send request if clicking on same button at your end.
  • (Forgot about we are dealing with scripts/HTMl) No caching in the picture
  • Clearing out resources?, yes it will be removed from DOM if appened in same section. But i guess it's necessary if same placeholder is used for each section content.
  • If you know that everytime each section will return same template again, you can create a local cache at client side just like memoization to see if template already exists.

Hope this helps.



来源:https://stackoverflow.com/questions/53758066/using-ajax-only-for-whole-website-optimal-or-not

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!