# Including javascript with plugin

**URL:** <https://forum.getkirby.com/t/including-javascript-with-plugin/4667>\
**Category:** Questions\
**Tags:** v2\
**Created:** [July 11, 2016, 7:32pm UTC](https://forum.getkirby.com/t/including-javascript-with-plugin/4667 "2016-07-11T19:32:53Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![SQBiz](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/sqbiz/32/5014_2.png) [@SQBiz](https://forum.getkirby.com/u/SQBiz)\
**Post date:** [July 11, 2016, 7:32pm UTC](https://forum.getkirby.com/t/including-javascript-with-plugin/4667/1 "2016-07-11T19:32:53Z")

</div>

I’m a little confused about how to include javascript alongside plugin functions. If I do this:

**myplugin/myplugin.php**

```auto
function myPluginFunction() {
 ...
}

js('/assets/plugins/myplugin/js/scripts.js')

```

**myplugin/assets/js/scripts.js**

```auto
console.log('success!');

```

it doesn’t work. This error comes up in the console:

`scripts.js:1 Uncaught SyntaxError: Unexpected token <`

and when I look at the resource in Dev Tools, it looks like this:

`<script src="http://project.dev/assets/plugins/myplugin/js/reset.js"></script>console.log('success!')`

I could always just load these scripts in my templates, but in this case I need to add a small bit of JS functionality to the panel.

What’s up?

---

<div class="post-metadata">

**Author:** ![1n3JgKl9pQ6cUMrW](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/1n3jgkl9pq6cumrw/32/2368_2.png) [@1n3JgKl9pQ6cUMrW](https://forum.getkirby.com/u/1n3JgKl9pQ6cUMrW)\
**Post date:** [July 11, 2016, 8:52pm UTC](https://forum.getkirby.com/t/including-javascript-with-plugin/4667/2 "2016-07-11T20:52:56Z")

</div>

Looks like your script is parsed outside the scoop.

I use it like this;

```auto
<?php

class MyField extends TextField {

  static public $assets = array(
    'js' => array(
      'my_script.js'
    )
  );

  public function content() {
...
  }

  public function input() {
...
  }
}

?>

```

**- edit -** Nevermind, this is the code for a field, not a plug-in. (still your code is rendered outside the scoop, 'though).

---

<div class="post-metadata">

**Author:** ![lukasbestle](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/lukasbestle/32/11437_2.png) [@lukasbestle](https://forum.getkirby.com/u/lukasbestle)\
**Post date:** [July 12, 2016, 12:28pm UTC](https://forum.getkirby.com/t/including-javascript-with-plugin/4667/3 "2016-07-12T12:28:37Z")

</div>

You can’t currently load JS into the Panel from a plugin, only from a field.

---

<div class="post-metadata">

**Author:** ![distantnative](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/distantnative/32/11319_2.png) [@distantnative](https://forum.getkirby.com/u/distantnative)\
**Post date:** [February 6, 2025, 4:57pm UTC](https://forum.getkirby.com/t/including-javascript-with-plugin/4667/4 "2025-02-06T16:57:34Z")

</div>

Archived on February 6, 2025, 4:57pm UTC


