59

I need to include a javascript file to webpage. I write the following:

include /../scripts/jquery.timeago.js

but I get

<script>/*
 * timeago: a jQuery plugin, version: 0.8.2 (2010-02-16)
 * @requires jQuery v1.2.3 or later
 *
 * Timeago is a jQuery plugin that makes it easy to support automatically
 * updating fuzzy timestamps (e.g. "4 minutes ago" or "about 1 day ago").
 *
 * For usage and examples, visit:
 * http://timeago.yarp.com/
 *
 * Licensed under the MIT:
 * http://www.opensource.org/licenses/mit-license.php
 *
 * Copyright (c) 2008-2010, Ryan McGeary (ryanonjavascript -[at]- mcgeary [*dot*] org)
 */
(function($) {
....
</script>

as result. But I need:

<script src="/Scripts/jquery.timeago.js" type="text/javascript"></script>

How to do it?

Oleg Sh
  • 8,496
  • 17
  • 89
  • 159
  • [`includes`](https://pugjs.org/language/includes.html) is used for including the content of one pug file into another. `script` is what you're looking for. – TheCrazyProgrammer Feb 23 '17 at 01:42

4 Answers4

97

Put this in your jade file:

script(src="/Scripts/jquery.timeago.js")

EhevuTov
  • 20,205
  • 16
  • 66
  • 71
11

You can put this code in your jade file:

   script(type='text/javascript' src='public/vendor/jquery/jquery.min.js')
Anubhav Singh
  • 1,006
  • 8
  • 11
10

Also, if you would like to include inline js within your jade file you could do the following as well:

script(type="text/javascript").
console.log('hello world');
Unheilig
  • 16,196
  • 193
  • 68
  • 98
Lawrence Chang
  • 459
  • 5
  • 7
2

Syntax for Adding scripts to your jade files is

script(src="",...,otherAttribute="")

example like the one below, that adds Jquery Bootstraps to the page.

  script( src="https://code.jquery.com/jquery-3.2.1.slim.min.js",  integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" ,crossorigin="anonymous")

script(src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js", integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q", crossorigin="anonymous")

  script( src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js" ,integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl", crossorigin="anonymous") 
random_user_name
  • 25,694
  • 7
  • 76
  • 115
C Williams
  • 850
  • 12
  • 19
  • Posting code only is a bit rude and not very helpful. Do you mind to explain? And may add a link to the documentation? – nicolallias Mar 06 '18 at 15:04
  • so sorry, I was just in a hurry, the syntax for adding scripts in Jade script(src="",...,otherAttribute="") And can be added to anywhere in the Html page, But codes above is just a quick way to add Jquery for bootstrap, and its best to add it just before the closing body tag. – C Williams Mar 06 '18 at 16:45