4

I've discovered that @import has performance implications. However all of my sass files @import a global-constants.scss at the top of the file to reuse several variables for colour and other properties, so that I can change the main colour etc from one place.

Is there a more performant way to reuse variables in sass?

EDIT: upon pondering this further, I notice that my css file that is generated from my sass file after compilation, has no import statement, and all of the variables are rendered as proper css values. So I'm probably not going to get any performance issues anyway, is my guess.

Community
  • 1
  • 1
BeniaminoBaggins
  • 11,202
  • 41
  • 152
  • 287
  • When you are using `@import` inside the SCSS, it will try to include the whole file and send it to the browser, if you have configured it to return only one single CSS file. That way, it is clean and better. – Praveen Kumar Purushothaman Dec 25 '16 at 01:10
  • @PraveenKumar I notice that my css file that is generated from my sass file after compilation, has no import statement, and all of the variables are rendered as proper css values. So I'm probably not going to get any performance issues anyway, is my guess. What are your thoughts? – BeniaminoBaggins Dec 25 '16 at 01:19
  • Added as an answer mate! `:)` – Praveen Kumar Purushothaman Dec 25 '16 at 01:24

1 Answers1

4

When you are using @import inside the SCSS, it will try to include the whole file and send it to the browser, (it is better, if you have configured it to return only one single CSS file or minified). That way, it is clean and better:

  1. No @import in the output.
  2. Source code is split using @import, keeping the modularity.

Summary: No performance issues because of @import.

Praveen Kumar Purushothaman
  • 164,888
  • 24
  • 203
  • 252