I have some css and js file in Sitecore, that I want to be loaded only in Experience Editor mode.

Any way of achieving this in SXA?

  • Are the js/css already on the pages -and if so, how?- now or is that step yet to be taken? Asking to know what our options are...
    – Gatogordo
    Sep 29 '20 at 11:47
  • no there are 2 files separately made for Experience Editor and i want them to get loaded only in Experience editor mode.
    – rahul
    Sep 29 '20 at 11:50
  • 1
    There is an Editing Mode theme you can add styles to. Sep 29 '20 at 12:19

A good way to add JS and CSS ony in Edit Mode for Experience Editor is to use the Editing Theme. It will be created along with your site and you can configure the one to be used on Settings item of your site. Furthermore you can create a theme using the CLI and point it to sync with the edit theme by tweaking the serverconfig.json


if you have a Custom layout (which probably you do), the easiest way is to add

@ AssetLinks assetLinks = AssetLinksGenerator.GenerateLinks(new ThemesProvider());
foreach (string style in assetLinks.Styles)
foreach (string script in assetLinks.Scripts)

The code above loads all the resources for your Theme. However, when the page is opened in Experience Editor, SXA automatically include resources set in your Site -> Settings -> Editing Theme field. That is where you add your custom theme with custom resources for Experience Editor. Note that your custom theme should extend /sitecore/media library/Base Themes/Editing Theme.

  • if i use this condition my styles will get loaded only for Experience Editor and for normal mode it will not load. I want to specify condition for particular file that needs to be loaded in Experience Editor.
    – rahul
    Oct 1 '20 at 10:55
  • I updated the the answer with response to your question.
    – Masoud
    Oct 1 '20 at 12:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.