Problem with external JavaScript with Jekyll

I have a site hosted by GitHub that uses Jekyll, and I (successfully) used an internally defined script in each layout that would generate a random label from an array of them.

I am trying to move this script to an external one tagline.js, but so far I have not been successful.

Here's the main tagline creating the script, in the event of something in the code causing it (which, to be honest, I doubt its simplicity, but it is always possible):

var tags = ['tag1', 'tag2', 'tag3'];

function getTag() {
    return tags[Math.floor(Math.random() * tags.length)];
}

$(document).ready(function() {
    $("#tagline").text(getTag());
});

As I said, it works great when it is internal, but does not work when I try to connect to the external. I am sure this is just the case when I indicate <script>: the HTML file containing <script>is in _layouts/default.html, but the script is in scripts/tagline.js.

EDIT: Sorry, I used " <link>" when I meant " <script>". Thus, this fixes the “you're using the wrong tag” solution !: P

EDIT2: full <script>(again, located in the HTML file at _layouts/default.html):<script type="text/javascript" href="../scripts/tagline.js"></script>

+5
source share
1 answer

The attribute you want to use to call the script is srcinstead href. For instance:

<script type="text/javascript" src="../scripts/tagline.js"></script>

( docroot), . , , . URL- docroot, /.

, http://example.com/scripts/tagline.js, :

<script type="text/javascript" src="/scripts/tagline.js"></script>

docroot , HTML , , . , , , .

+4

All Articles