AJAX AddCssCommand may fail if asset path does not end in .css

Created on 26 October 2023, 7 months ago
Updated 3 May 2024, 20 days ago

Problem/Motivation

The add_css() method passes the verbatim URL of a CSS asset to loadjs(). This can be a problem for URLs that do not end in .css - loadjs may not realize it should be treating it as a CSS asset. This can lead to the asset being blocked by the browser, on account of a MIME type mismatch.

See https://github.com/muicss/loadjs/issues/39 for an issue in the loadjs repository discussing this same problem.

Steps to reproduce

  • Declare a library with an extension-less CSS asset, e.g. https://fonts.googleapis.com/css?family=Merriweather:400,700
  • Load the library in an AJAX call. (My particular use case: CKEditor5 libraries are not always loaded immediately, but may be loaded in an AJAX call, e.g. un-collapsing a Paragraph.)

Proposed resolution

I think this could be a simple fix. loadjs can be forced to regard any file as a CSS asset by prepending "css!" to the start of a URL. As far as I know, it is expected all URLs passed to add_css() to be CSS files. If that assumption is correct, ajax.js could be changed to prepend the "css!" modifier for all assets.

Remaining tasks

User interface changes

API changes

Data model changes

Release notes snippet

πŸ› Bug report
Status

Closed: outdated

Version

11.0 πŸ”₯

Component
AjaxΒ  β†’

Last updated 1 minute ago

Created by

πŸ‡ΊπŸ‡ΈUnited States bvoynick

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Production build 0.69.0 2024