(Vegvisir 2, Vegvisir 3)

VV::js()

Import and minify a JavaScript file.

The syntax is identical to VV::css(), and VV::embed().

Description

VV::js() imports and minifies a JavaScript file and returns it as a string.

Parameters

pathname

Path to a JavaScript file to import relative from project root.

Example

relative

Path provided to pathname will be a relative when this parameter is true (default). Set to false to make path absolute.

Example

Return values

string

A string containing minified JavaScript. Please note that linebreaks are preserved.

Will return an empty string if the path provided to pathname is not a valid JavaScript file, or if it failed to import.

Example

Examples

Basic usage

Let's take the following JavaScript file and put it into a page.

By using VV::js() inside a script, we've enabled the code for that specific page.