Problem/Motivation
When JavaScript aggregation is enabled (typically on production environments), Drupal throws an exception when trying to optimize the external CDN JavaScript files defined in search_api_typesense.libraries.yml:
Error trying to optimize JavaScript asset: https://cdn.jsdelivr.net/npm/algoliasearch@4.20.0/dist/algoliasearch-lite.umd.js. Only file JavaScript assets can be optimized.
The error occurs in Drupal\Core\Asset\JsOptimizer->optimize() because the optimizer attempts to process external URLs as local files.
Steps to reproduce
1. Enable the search_api_typesense module in Drupal 11.3.1
2. Enable JavaScript aggregation (/admin/config/development/performance)
3. Visit a page that loads the search_api_typesense/instantsearch library
4. Observe the exception in the logs
Proposed resolution
The external JavaScript files in search_api_typesense.libraries.yml need to be marked with type: external attribute:
instantsearch:
js:
https://cdn.jsdelivr.net/npm/typesense-instantsearch-adapter@2/dist/typesense-instantsearch-adapter.min.js: { type: external }
https://cdn.jsdelivr.net/npm/algoliasearch@4.20.0/dist/algoliasearch-lite.umd.js: { type: external }
https://cdn.jsdelivr.net/npm/instantsearch.js@4.60.0/dist/instantsearch.production.min.js: { type: external }
See: https://www.drupal.org/docs/develop/creating-modules/adding-assets-css-j...
Remaining tasks
- Apply the fix to search_api_typesense.libraries.yml
- Review and commit
| Comment | File | Size | Author |
|---|---|---|---|
| search_api_typesense-external_js.patch | 932 bytes | norbert-goco |
Issue fork search_api_typesense-3565794
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #4
lussolucaComment #7
lussolucaCommitted and merged to 1.0.x. Thanks!