All-in-one location/hashchange history management library

前端 未结 7 557
礼貌的吻别
礼貌的吻别 2020-12-23 13:55

First of all, I know there\'s libraries that provide polyfills for location.pushState/popState (History.js, Hash.js, jQuery hashchange), so please

7条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-23 14:18

    PJAX is the process you're describing.

    The more advanced pjax techniques will even start to preload the content, when the user hovers over the link.

    This is a good pjax library. https://github.com/MoOx/pjax

    You mark the containers which need will be updated on the subsequent requests:

    new Pjax({ selectors: ["title", ".my-Header", ".my-Content", ".my-Sidebar"] })
    

    So in the above, only the title, the .my-header, .my-content, and .my-sidebar will be replaced with the content from the ajax call.

    Somethings to look out for

    Pay attention to how your JS loads and detects when the page is ready. The javascript will not reload on new pages. Also pay attention to when any analytics calls get called, for the same reason.

提交回复
热议问题