Skip to content

Different scripts for different pages? #46

Answered by PaperStrike
HEIGE-PCloud asked this question in Q&A
Discussion options

You must be logged in to vote

The easiest solution would be wrapping the parts that differ among pages into an element that you will add to the selectors option. Make sure to have the wrapper existing on each page. In your example, that could be

<!-- page 1 -->
<div class="differ-among-pages"></div>
<script src="pjax.js"></script>
<script src="theme.js"></script>

<!-- page 2 -->
<div class="differ-among-pages">
  <script src="lightgallery.js"></script>
</div>
<script src="pjax.js"></script>
<script src="theme.js"></script>

don't forget to select that element like:

const pjax = new Pjax({
  selectors: [
    '.differ-among-pages',
  ],
});

#31 (comment) shows two other possible solutions.

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by HEIGE-PCloud
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants