What is pjax?
Simply put, it uses ajax technology to fetch documents from the server, updating the current page without refreshing the browser page, and ensures that files such as the page's js and css are not loaded repeatedly. Then, using the pushState feature provided by the browser, it updates the URL and ensures that users can go back to historical pages by clicking the back button.
Why use pjax?
pjax can bring a better experience. Loading a new page does not require reloading css and js, making the website faster. Because the entire page does not need to be refreshed, the page loading speed is greatly improved.
How to use pjax?
The method of use is very simple.
First, call the jQuery and pjax package code.
Nothing else needs to be set up, just go straight to the code.
Add the following resource import code inside the website's head tags:
<script type="text/javascript" src="https://cdn.gqink.cn/jQuery/jquery.min.js"></script> <script type="text/javascript" src="https://cdn.gqink.cn/jQuery/jquery.pjax.min.js"></script>
Next, add the following code before the </body> tag.
That is, at the footer of the website.
<script type="text/javascript"> //这里的#id代码局部刷新的内容 $(document).pjax('a[target!=_blank]', '#id', {fragment: '#html',timeout: 8000}); $(document).on('pjax:send', function() { //$('#loading').show(); // 将#loading的内容显示 加载动画 }); $(document).on('pjax:complete', function() { //$('#loading').hide(); // 将#loading的内容隐藏 加载动画 //页面刷新后有些函数没有调用在这里可以写上你的函数让他重新加载 }); </script>
I will not go into the loading animation here. Research it yourself; just add an emoji and write an animation.