How to run this javascript offline

javascript

I'd like to have offline the functionality of this javascript: jspretty. I know that I can get the same online, but I want it offline.

How can I run the js above?

Best Answer

  1. Save the code in the link to a file with a js extension. Example: jspretty.js

  2. Place the .js file in a folder on the local computer that is accessible over a local web server. i.e. usually in a folder like: c:\inetpub\wwwroot\, c:\apache\htdocs\, c:\xampp\htdocs\, c:\wamp\www\, /var/www/ etc. (These are only examples of some default web server paths and is ok for development environments IMO. But not recommended for production environments)

  3. Refer to that local .js file on a web page using absolute or relative paths.

Example:

<script src="http://localhost/folder/jspretty.js">

or

<script src="jspretty.js">

or

<script src="/folder/jspretty.js">

or

<script src="../jspretty.js">

or

<script src="../folder/jspretty.js">

For details on relative and absolute paths see:

  1. Difference between Relative path and absolute path in JavaScript
  2. Absolute vs relative URLs
  3. Paths and URLs; relative and absolute
Related Question