Reputation: 114
As I don't know javascript at all, I'm wondering if it's possible to insert some SSI into javascript in a PHP file. I've got a bit of script going to preload some images, and I'd like to set it up so that some images always get preloaded across my entire site (via the SSI) of which I may add to over time, while allowing me to add individual images as needed page by page. It works fine in my HTML files, but not it my PHP files.
Here's what I've got in my HTML files which works just fine:
<script>
function preload(arrayOfImages) {
$(arrayOfImages).each(function () {
$('<img/>')[0].src = this;
});
}
preload([
<!--#include virtual="/grabbag/preload-images.html" -->
'/images/image-1.png',
'/images/image-2.png'
]);
</script>
But this doesn't work in my PHP files, the SSI getting replaced with nothing but empty text:
<script>
function preload(arrayOfImages) {
$(arrayOfImages).each(function () {
$('<img/>')[0].src = this;
});
}
preload([
<?php include("/grabbag/preload-images.php"); ?>
'/images/image-1.png',
'/images/image-2.png'
]);
</script>
Is this possible? Thanks in advance.
Upvotes: 1
Views: 262
Reputation: 4134
Your PHP include is absolute. It begins with a / and therefore it'll look in the root (the up most path) and tries to traverse down. Change it to a relative one or the correct absolute one and a it'll work 😉
Upvotes: 1