Legacy/Node.js

express ejs에서 PJAX 사용시 header 및 footer 조건부 include하기

Foo 2017. 1. 14. 21:12
728x90
<% if(!req.header('X-PJAX')) { %>
  <%- include('header.ejs'); %>
<% } %>

라고 해주면 조건부로 include를 할 수 있다.

그 이유는?

위와 같이 PJAX 요청을 날릴 경우

X-PJAX: true

라는 헤더값이 request에 들어가 있기 때문에 구분할 수 있다.

때문에 일반적인 요청에는 Header, Footer를 집어넣고, PJAX요청에는 내용만 가져오도록 할 수 있다.


ref

http://pjax.herokuapp.com/

https://github.com/defunkt/jquery-pjax

https://github.com/MoOx/pjax

https://ntotten.com/2012/04/09/building-super-fast-web-apps-with-pjax/


http://ejs.co/