Search code examples
phpjquerybootstrap-4cdn

CDN links in php include files


I am working a site project with Bootstrap 4.4.1. I use the CDN links to place them right before closing the </body>. In order to avoid lots of coding in all pages, I want to use a php include file which contains all the scripts below/ This file I named "js-remote.php". This is inside a folder called "js".

I inserted the code on every content page (I am doing all php pages) and the path is:

<?php include '../js/js-remote.php'>

But doesn't work. I have navigation bar also as included file, the menu is shown but the dropdowns don't work properly. Even when I paste the full scripts codes of the CDN (without using any php include) don't work either.

ONLY works when I don't use the include files, just when pasting the complete code as a regular html file.Get below the code I wanna use in a php include file. Observations, please.

<script src="https://code.jquery.com/jquery-3.4.1.slim.min.js" integrity="sha384-J6qa4849blE2+poT4WnyKhv5vZF5SrPo0iEjwBvKU7imGFAV0wwj1yYfoRSJoZ+n" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/popper.js@1.16.0/dist/umd/popper.min.js" integrity="sha384-Q6E9RHvbIyZFJoft+2mJbHaEWldlvI9IOYy5n3zV9zzTtmI3UksdQRVvoxMfooAo" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/js/bootstrap.min.js" integrity="sha384-wfSDF2E50Y2D1uUdj0O3uMBJnjuUD4Ih7YwaYd1iqfktj0Uod8GCExl3Og8ifwB6" crossorigin="anonymous"></script>
</body> 

But instead of pasting the whole scripts I just want to put one single line:

<?php include '../js/js-remote.php' ?>
</body>
<--! Could it work?-->

Where "js-remote.php" is a page which contains all the cdn scripts above and more coming in the future.

Sorry for the redundance but it's necessary. The "js-remote.php" file contains:

<script src="https://code.jquery.com/jquery-3.4.1.slim.min.js" integrity="sha384-J6qa4849blE2+poT4WnyKhv5vZF5SrPo0iEjwBvKU7imGFAV0wwj1yYfoRSJoZ+n" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/popper.js@1.16.0/dist/umd/popper.min.js" integrity="sha384-Q6E9RHvbIyZFJoft+2mJbHaEWldlvI9IOYy5n3zV9zzTtmI3UksdQRVvoxMfooAo" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/js/bootstrap.min.js" integrity="sha384-wfSDF2E50Y2D1uUdj0O3uMBJnjuUD4Ih7YwaYd1iqfktj0Uod8GCExl3Og8ifwB6" crossorigin="anonymous"></script>

Solution

  • I see errors in the way the code is written here that would break the functionality if they're in the actual document. The include should be written

    <?php include '../js/js-remote.php'; ?>
    

    In your post you left out the semicolon and ?> in the first case and the final quote and semicolon in the second.