Auto remove BOM added by Sass to avoid issues on CSS aggregation

Created on 7 October 2015, about 9 years ago
Updated 27 March 2023, over 1 year ago

Problem/Motivation

Since Sass 3.4 some of the generated CSS files contains a BOM flag to be compliant with CSS Syntax Module Level 3. The problem is that Drupal's CSS aggregator does not remove that flag. It that case, some CSS rules, often related to webfonts, are not loaded anymore.

Proposed resolution

An easy hack can be added in the config.rb file to remove the BOM automatically.

# Removes the BOM for UTF-8 stylesheets.
on_stylesheet_saved do |filename|
  css     = File.open(filename, 'r')
  content = css.read
  if "UTF-8" == content.encoding.name
    content.sub!("\xEF\xBB\xBF".force_encoding("UTF-8"), '')
    File.write(filename, content)
  end
end

Remaining tasks

Add this snippet to the base config.rb file.

User interface changes

None.

API changes

None.

Data model changes

None.

📌 Task
Status

Active

Version

4.0

Component

Code

Created by

🇫🇷France duaelfr Montpellier, France

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

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024