When ajax extracted the page for the second time, main.js did not reload, or all js did not have the problem of reloading.

  node.js, question

Effect diagram:
When using Ajax as a drawer effect, js did not reload when extracting the page for the second time. How to solve this problem?

My blogSimilarpjaxTechnology, the original design also encountered similar problems.

In fact, the root cause is not that js has not reloaded. In fact, JS does not need to reload at all because it has already been loaded.
The root cause is that it will not be re-executed.

You can define a file calledbootstrap.js.
Then re-execute js that need to be reloaded one by one inside.
Ps If there is code written in the public area before, that is, it does not belong to any function, you need to package it into a function and execute it here.
For example:


This js has actually been loaded and executed. Under normal circumstances, it will not be executed again.
Then you need to modify it to

var initAJs=function(){

Then it will be executed when pjax returns successfully.