Issue
- Need to use external JavaScript libraries that are uploaded to Documents and Media in fragments.
Environment
- Liferay DXP 7.4
Resolution
To include external JavaScript libraries stored in Documents and Media within a fragment:
- Upload your JavaScript (.js) and CSS (.css) files to Documents and Media.
- In your fragment's HTML or Javascript, add
<script>
and<link>
tags to reference the files, using the full URL to the latest version as thesrc
orhref
attribute.- To obtain the correct URL of the files:
- Go to Site Menu > Content & Data > Documents and Media.
- Click the file's name to open the preview.
- In the file preview, click the Info button (i icon).
- Copy the URL displayed next to "Latest Version URL".
- To obtain the correct URL of the files:
Additional Information
For more robust JavaScript library management, particularly in production environments, consider using JavaScript import maps. This approach offers better organization, version control, and caching capabilities. Refer to these resources for more information: