Add pjax for faster page loads

This commit is contained in:
Tom Raithel
2017-02-13 09:23:56 +01:00
parent 292a2b045c
commit f8c5bb7855
6 changed files with 30 additions and 3 deletions

View File

@@ -1,4 +1,6 @@
import Vue from 'vue';
import applyPjax from './pjax';
const initFilter = element => {
const index = JSON.parse(element.getAttribute('data-index'));
@@ -24,6 +26,12 @@ const initFilter = element => {
return visibleItems.length > 0;
},
},
created() {
applyPjax();
},
updated() {
applyPjax();
},
});
};

10
js/pjax.js Normal file
View File

@@ -0,0 +1,10 @@
import Pjax from 'pjax';
const applyPjax = () => {
new Pjax({
elements: '.js--body a',
selectors: ['title', '.js--body'],
});
};
export default applyPjax;

View File

@@ -1,8 +1,16 @@
import filter from './filter';
import applyPjax from './pjax';
const enhanceComponent = (selector, enhancer) => {
const $filter = [].slice.call(document.querySelectorAll(selector));
$filter.map(enhancer);
}
enhanceComponent('.js--filter', filter);
const enhanceComponents = () => {
enhanceComponent('.js--filter', filter);
}
applyPjax();
enhanceComponents();
document.addEventListener("pjax:success", enhanceComponents);