What is PJAX and how to detect a PJAX call in the back end?

Asked

Viewed 594 times

8

I’ve been reading about PJAX, but it is a little confusing its operation independent of frameworks, I saw articles but all turned to YUI or plugins for jQuery, really it was not very clear its implementation.

If I understand correctly PJAX is the interaction of the DOM (through javascript) with the back-end through the XmlHttpRequest.

What I’d like to understand:

  • It should be used with pushState or this is just a kind of implementation?
  • It is used to load HTML content (the plugins I tested loaded the data into a pointed element)?
  • I know I must have to send header through the setrequestheader, but I saw two different headers being used, so how to "detect" a PJAX call? (I know that in real there is no way to differentiate a request XmlHttpRequest of other types of requisition)

1 answer

3

PJAX is an acronym for Pushstate Ajax, and is nothing more than the combination of existing methods and technologies:

  1. The method Pushstate belongs to API History HTML5 and with it you can manage the URL and history stack of a website. ¹
  2. AJAX stands for Asynchronous Javascript and XML. In a nutshell, it is the use of the Xmlhttprequest object to communicate with server-side scripts. ²

It should be used with pushState or this is just a kind of implementation?

Yes, it should be used with Pushstate. I believe that in this question you have confused with HTTP protocols Stateless and Stateful. ³

It is used to load HTML content (the plugins I tested loaded the data into a pointed element)?

It is used to load server content, asynchronously, using the characteristics of the Pushstate method for a better front-end experience

I know I must have to send header through setrequestheader, but I I saw two different headers being used, so how to "detect" a called PJAX? (I know that in real there is no way to differentiate a Xmlhttprequest request for other types of request)

In the methods implemented in most frameworks, it is possible to detect a PJAX call through HEADER X-PJAX

¹ Source

² Source

³ Source

Browser other questions tagged

You are not signed in. Login or sign up in order to post.