Site logo

Archived topic

Elements - adding js files in footer for one page on site

4 replies · Started by Denise on February 1, 2020

Viewing posts 1–5 of 5

Hello GP Friends,

I am using DataTables to create an index on my site: Explore AI Ethics. I need to reference the .js scripts, but only for the index page, not the entire site. What is the best way to do this? For now, I created an Element to put the code in the footer and display on just the Index page. It seems to be working, but I'm not sure if this is the is optimal for speed, etc.

Thanks,
Denise

-----------------------------------------------------
<!-- DataTables CSS -->
<link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/1.10.18/css/jquery.dataTables.min.css"/>
<link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/select/1.2.6/css/select.dataTables.min.css"/>
<link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/buttons/1.5.4/css/buttons.dataTables.min.css"/>
<link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/responsive/2.2.2/css/responsive.dataTables.min.css"/>

<!-- DataTables plugin and extensions -->
<script type="text/javascript" src="https://cdn.datatables.net/1.10.18/js/jquery.dataTables.min.js"></script>

<!-- DataTables select rows -->
<script type="text/javascript" src="https://cdn.datatables.net/select/1.2.6/js/dataTables.select.min.js"></script>

<!-- DataTables buttons -->
<script type="text/javascript" src="https://cdn.datatables.net/buttons/1.5.4/js/dataTables.buttons.min.js"></script>
<script type="text/javascript" src="https://cdn.datatables.net/buttons/1.5.4/js/buttons.html5.min.js"></script>
<script type="text/javascript" src="https://cdn.datatables.net/buttons/1.5.4/js/buttons.print.min.js"></script>

<!-- DataTables responsive -->
<script type="text/javascript" src="https://cdn.datatables.net/responsive/2.2.2/js/dataTables.responsive.min.js"></script>

And is the code that I pasted the correct way to reference the files?

Hi there,

I don't see any issues with doing it this way.

However, that's a lot of JS to load - I would recommend finding a way to trim that down.

Let me know if you need more info :)

Thanks, Tom.

No problem :)

This archived topic is closed to new replies.