ePublishing Knowledge BaseePublishing Knowledge Base AdvancedHow do I update javascript files on my website?

How do I update javascript files on my website?

If you have high in-house technical skills, access two files to have a dramatic impact on your website without additional development from ePublishing.

  • One is the CSS (Cascading Style Sheets), which is hosted in the Media Manager. Look for a file called yourdomainname.css.
  • The other is your Javascript file, which is also in the Media Manager. Look for a file called client.js.

The intent of the client.js file is to allow your team to manipulate javascript. All javascript you add should go in this file.

This article covers how to update the second of the two: Javascript. Only advanced users should update the Javascript on their websites. If you have questions, please contact your ePublishing solutions manager.

1. Access your Media Manager under Editorial.

Access your Media Manager under Editorial.

2. In the Media Manager, under the /javascripts directory, a file exists called client.js. Do not rename this file.

If you don't see the file, you can add it. The site's templates will only use it if it exists in the Media Manager.

This file is used by every website template, which allows you to add any needed Javascript function that can be called by any content on your website.

3. Update the Javascript file.

NOTE: This is to be used by advanced users only. Changes made to this file can have dramatic impacts on your website. If you submit a support request to fix problems that stem from this file, any time researching and fixing the problem will be considered billable.

 

 

3.1. JQuery and other libraries?

jQuery is already included in the core of the site, linking to another version will cause conflicts.

To include a 3rd party script, we have a special function for this. Most modern scripts support AMD or CommonJS. Our scripts expect AMD, so importing a script traditionally in the source will likely break. Instead, use the following snippet in your client.js file to include another script:

window.epub.clientRequire('/ext/resources/javascripts/path-to-file.js')

Requiring this script returns a jQuery AJAX Promise. If you need to make sure the script has loaded before loading additional code, like setting up a jQuery plugin, you could do the following:

window.epub.clientRequire('/ext/resources/javascripts/path-to-file.js').then(function(){
// custom code here
// e.g. init jQuery plugin
$('#some-id').myCustomPlugin();
});

4. CAUTION: Changes should not modify the DOM or core templates.

The contents of this file should not modify the DOM or core templates, other than Editorial Content Zones, or WYSIWYG controlled content. As core code is continuously updated over time, as a result any conflict that arises from this file will be considered billable.

As we are continuously updating and improving our core templates and functionality, any javascript changes you make to control content other than editorial content zones or WYSIWYG controlled content may break. You are responsible for making sure your added javascript code continues to function with our site.