---
title: "Easily Add PJAX No-Refresh Loading to Your Website"
url: https://www.geekcorelab.cn/en-US/post/simply-add-pjax-without-refresh-loading-to-the-website
updated: 2026-11-04T02:24:17.385166Z
author: "hhjmk"
summary: "pjax是一种利用ajax技术更新页面内容的技术，无需刷新浏览器即可获取并更新文档，同时避免重复加载js和css文件，并通过pushState功能更新URL和实现历史记录回溯。使用pjax能提升网站速度和用户体验，因为无需重新加载整个页面。实现方法包括引入jQuery和pjax库，并在文档头部和底部添加相关代码，设置局部刷新内容和加载动画。"
---

# Easily Add PJAX No-Refresh Loading to Your Website

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.
