Place CSS Design File in Safe Edit


(Greg Roberts) #1

Hi,

 

I've just noticed a weird quirk where I can place a Matrix 'CSS File' asset into Safe Edit but not a 'CSS Design File' asset. Has this always been the case? I don't remember this being a problem before...

 

Being able to place a CSS file into Safe Edit, so changes can be made and previewed in dev, before sending live makes a big difference.

 

The alternative is duplicating design files and CSS files to create a separate dev area, but this can be difficult if you have a lot of design files and settings.

 

Can anyone explain this behaviour or a potential work-around?


(Tim Davison) #2

Yes.  It is true that CSS Design files (as well as site Design files aka parse files) cannot be placed into Safe Edit, and has been for as long as I can recall.  And I agree it's a massive problem.  To the point that I avoid CSS Design files completely, and will not take on any sites to support that use them (at least until we get a chance to swap them over).

 

What I do now for css files is use Standard Page assets - I know, but hear me out!  You write CSS as per normal on but instead of using 'mysource_files' for the URL's etc use './?a=' syntax instead.  The rest is just basic CSS.

  • Create a Std Page asset with raw HTML
  • Apply custom design that sets the MIME type to text/css
  • Apply caching headers so it's cached for a long period of time by Matrix cache and Squid proxies (if you have them), and set the browser cache to a relatively small period of time.  Use Squid accelerator headers to ensure the Squids store it for a long time and not use the browser cache.

Performance!! I can hear you say.

  • Matrix cache is fast, Squids even faster, so there's minimal performance hit for this approach vs apache __data area.
  • Smaller browser cache ensures currency of file.
  • Longer accelerator cache ensures minimal (no??) performance hit on the servers.
  • Granted you do lose the ability to return 304 responses, but since the major contributor to latency in particular for mobile or slower networks is the http request, not the amount downloaded, the performance loss is negligible.  (if you were really worried you could increase the browser cache header value up - my testing shows it's literally milliseconds of difference, and by combining multiple css components together you can reduce the number of http calls even further, which more than offsets any loss in performance.  But let's be real, we're discussing a few bytes/milliseconds - usually stripping out or minimising a single image will have drastically more impact)
  • [UPDATE - added] Note that there is literally no performance difference between this approach and using a CSS Design File as a CSS Design file is not served as a static file anyway, so it always returns to the Matrix cache (or proxy if you have one).  In other words, neither responds with a 304 (at least in my version of Matrix).
  • [UPDATE - added] Approach above responds *very* favourably from proxies (Squids) on the front of the Matrix instance.  Response time is incredibly quick, and the accelerator settings keep the number of hits on the Matrix cache low.

Benefits:

  • You can now Safe Edit.
  • Images/fonts referenced in css no longer have to be under the css parse file.
  • Images/fonts references now show NOTICE links when they are included in a css file this way (no more "anyone using this font?  How 'bout I just delete it and see").
  • You have access to all keywords available in a Std Page asset, which leads to...
  • Able to insert/combine multiple css components together (reducing http calls required, page load performance benefit), which leads to...
  • Able to use keyword modifiers to replace pre-configured 'tokens' in css components, kinda like a pre-compiler/SASS/etc.  We re-use a set of core css/js plugins we've developed in-house, and are able to customise them for each site.  In particular we can adjust css breakpoints with just a few numbers, spin up the entire framework within a few minutes.

We use the above approach for our JS files as well.  Have had incredible success so far.  I've kept the option to increase browser cache time much higher, but so far performance has never been an issue.  Sites using this approach have the fastest page load times I've ever developed (not *because* of this approach, my point is it's not hurting it).

 

(Sorry if anything doesn't make sense - it's late).


(Greg Roberts) #3

Hi Tim, thanks for sharing. I am blown away by your approach to CSS files within Matrix, which you have so clearly detailed. I'll definitely consider this for my next implementation.

As there appear to be clear benefits to your approach above, I wonder why Squiz has architectured CSS Design Files the way they have? Would be interested to hear from someone within Squiz regarding a suggested approach?


(Tim Davison) #4

I think it may not be a case of CSS Design File engineered this way, but more of a legacy implementation that so far hasn't needed to be updated.  Squiz will talk about 'old' and 'new' asset types.  Newer ones obviously have a lot more features and work better.  I know Squiz has recently added the CSS File Folder and JS File Folder assets which were a nice improvement (but which I personally found very hard to use), and there is a git bridge coming, so things are definitely getting updated.  I think as demand grows Squiz updates their assets.

 

One of the major cons of my approach is you can't export or import an entire design via a tar file.  Since I use a LOT of nested pages and asset listings, etc in site designs anyway we would never do this, but it may be an issue for others.


#5

I’ll dig up some advice that Scotty provided regarding CSS files and performance. I know that ideally if it not associated with the design that you can just use a txt file ( which is safe editable and fast)

You can take a performance hit when using CSS design files and I know is the past there have been pros and cons against them.


#6

Hi Tim,

 

I just thought also we have CSS design files as well and there was never any problem placing them in safe edit, however static caching is off.

 

Checking on advice Scotty and mickey provided in the past was pertaining to references of images in  style sheets - apologies. But Mickey did say  you wanted to use /my_source files paths in stylesheets you need to use CSS file assets. If not you could use a txt file asset. This would allow you to place your css into safe edit without having to worry about file paths changing and your design breaking.

 

I just did a test to reconfirm and yes that is all good =)

 

Scotty had also said in the path using globals keywords to generate a URL is better than using  just the asset ID.

 

Sorry for chiming in on the post.