minify css

267 views
Skip to first unread message

Venmore

unread,
Nov 25, 2016, 5:48:06 PM11/25/16
to BBEdit Talk
Hi
What is the best way to do this within BBEdit please?
Can it be done on save/export whilst keeping original format for easy editing?
Any pointers gratefully received.

Regards
Carl

Greg Raven

unread,
Nov 25, 2016, 11:41:20 PM11/25/16
to BBEdit Talk
Try Optimize. It's not perfect, but it's darned good, and you can CSS -> Format your CSS anytime you need to edit it, and then just Optimize it again before uploading. For auto optimizing, try Codekit or HammerForMac.

Venmore

unread,
Nov 26, 2016, 6:55:56 AM11/26/16
to BBEdit Talk
Thanks Greg
Will try out
Cheers
Carl

Greg Raven

unread,
Nov 26, 2016, 9:22:36 AM11/26/16
to BBEdit Talk
One benefit of using Markup -> Utilities -> Optimize is that it preserves the comments in your CSS file. This of course means your CSS file will not be as small as it could be, but after you apply Markup -> CSS -> Format, they will still be there.

With CodeKit, you would rename your CSS file to have a SCSS extention (that is, style.css would become style.scss), and you would tell CodeKit to process it to style.css (in this example), which would result in a smaller CSS file. You then do your editing in the SCSS version, with CodeKit automatically minifying it each time you save.

For most purposes, though simply optimizing seems to be fine, especially if you enable browser caching in your .htaccess file, or use a service such as Cloudflare or Incapsula as part of your DNS chain.

Luis Speciale

unread,
Nov 26, 2016, 9:33:48 AM11/26/16
to bbe...@googlegroups.com
I use pleeease
http://pleeease.io/

Hope it helps

Greg Raven

unread,
Nov 27, 2016, 9:16:17 PM11/27/16
to BBEdit Talk
Theoretically, it looks as though it should be possible to use BBEdit's "Attaching Scripts to Events" capability (page 294 in the manual) -- specifically, the documentDidOpen and documentWillSave attachment points -- in AppleScript Attachment Scripts to do automatic pre- and post-processing of *.css files. However, my AppleScript skills are non-existent, so the proof is left to the reader.

Christopher Stone

unread,
Nov 29, 2016, 6:47:43 PM11/29/16
to BBEdit-Talk
On Nov 25, 2016, at 16:48, Venmore <ven...@gmail.com> wrote:
What is the best way to do this within BBEdit please?
Can it be done on save/export whilst keeping original format for easy editing?


Hey Carl,

With AppleScript and/or Shell-Text-Filters the sky is the limit.

I don't write CSS, so I don't have any solutions in-hand – but I heavily customize everything possible with AppleScript, Shell-Scripts, and UI-Automation via Keyboard Maestro.

What tool(s) if any are you using now?

--
Best Regards,
Chris

Vlad Ghitulescu

unread,
Nov 30, 2016, 3:02:49 AM11/30/16
to BBEdit Talk
On 26 Nov 2016, at 5:41, Greg Raven wrote:

> For auto optimizing, try Codekit or HammerForMac.

+1 for CodeKit (https://codekitapp.com)

And: http://www.htmlcompressor.com/compressor/ does both HTML (what
CodeKit doesn't yet) and CSS.

@lbutlr

unread,
Dec 2, 2016, 1:47:16 AM12/2/16
to bbe...@googlegroups.com
On 11/25/16 3:48 PM, Venmore wrote:

> What is the best way to do this within BBEdit please?

Coming back to this, Why?

CSS is taxt, and text is small. A single small graphic on a page is
probably more data than all the CSS, so you're not saving anything by
squishing it down to remove a few EOLs and maybe some spaces. Add to
that that nearly all webservers compress the data and you're saving
practically nothing, if anything at all.


Steve Piercy

unread,
Dec 2, 2016, 2:26:44 AM12/2/16
to bbe...@googlegroups.com
On 12/1/16 at 11:47 PM, (unknown sender) pronounced:
Yup. The number of HTTP requests is a major factor in
performance. The tool Google PageSpeed Insights is helpful.
https://developers.google.com/speed/pagespeed/insights/

Tools like webpack, gulp, or grunt automate static asset optimization.
https://webpack.github.io/

Google PageSpeed web server module, if your server supports it,
can squeeze out every last drop of optimization of static assets
when served.
https://developers.google.com/speed/pagespeed/module/

--steve

------------------------
Steve Piercy, Soquel, CA

Greg Raven

unread,
Dec 2, 2016, 7:01:42 AM12/2/16
to BBEdit Talk
The number of HTTP requests is a major factor when using HTTP 1.1. I hear this will cease to be a factor with HTTP 2.0.

Venmore

unread,
Dec 11, 2016, 2:43:54 PM12/11/16
to BBEdit Talk
Hi Lewis
Text is small but you will get lower rankings on Google if your site files are not optimised.
Carl

@lbutlr

unread,
Dec 11, 2016, 3:53:57 PM12/11/16
to bbe...@googlegroups.com
On Dec 11, 2016, at 12:43 PM, Venmore <ven...@gmail.com> wrote:
> Text is small but you will get lower rankings on Google if your site files are not optimised.

According to whom?

Venmore

unread,
Dec 11, 2016, 6:46:26 PM12/11/16
to BBEdit Talk
Google back in 2010 and since then numerous online authorities
https://webmasters.googleblog.com/2010/04/using-site-speed-in-web-search-ranking.html

I recently did this across a 200 page website. Within a month we saw it's ranking position increase and thus user numbers.
 
All I am looking for was the ability to do this within BBEdit...

Greg Raven

unread,
Dec 12, 2016, 7:09:14 AM12/12/16
to BBEdit Talk
With your CSS file open and active:

Markup -> Utilities -> Optimize.

Rick Yentzer

unread,
Dec 12, 2016, 8:12:52 AM12/12/16
to BBEdit Talk
This is bad advice.

Javascript is also just text, but the developer should always look for ways to improve site loading speed and performance. Minification of CSS and JS and even HTML is standard within the web development industry. 

Christopher Stone

unread,
Dec 12, 2016, 5:25:44 PM12/12/16
to BBEdit-Talk
On Nov 25, 2016, at 16:48, Venmore <ven...@gmail.com> wrote:
What is the best way to do this within BBEdit please?
Can it be done on save/export whilst keeping original format for easy editing?


Hey Carl,

It looks like the yuicompressor java module is one of the more highly regarded compressors.  (Of course you must have Java installed for it to work.)

See the downloads area on this page: https://github.com/yui/yuicompressor/releases

Using it in a BBEdit text filter is simple enough:

-------------------------------------------------------------------------------------------

#!/usr/bin/env bash

java -jar ~/Downloads/yuicompressor-2.4.8.jar --type css --charset utf8

-------------------------------------------------------------------------------------------

Give it a keyboard shortcut and go-to-town.

-------------------------------------------------------------------------------------------
# An AppleScript version:
-------------------------------------------------------------------------------------------

set bbeditText to bbeditFrontWinText()
set shCMD to "java -jar ~/Downloads/yuicompressor-2.4.8.jar --type css --charset utf8 <<< " & quoted form of bbeditText
set minifiedCSS to do shell script shCMD

# Do whatever you want with the minifed css.

-------------------------------------------------------------------------------------------
--» HANDLERS
-------------------------------------------------------------------------------------------
on bbeditFrontWinText()
   tell application "BBEdit"
      tell front document to its text
   end tell
end bbeditFrontWinText
-------------------------------------------------------------------------------------------

* Note that you should pick a more permanent path for the yuicompressor module.

--
Best Regards,
Chris

Rick Yentzer

unread,
Dec 13, 2016, 7:39:48 AM12/13/16
to BBEdit Talk, listm...@suddenlink.net
Christopher,
I'm envious of your AppleScript and shell knowledge. You always have a solution for those on this board. Kudos!

Rick

Venmore

unread,
Dec 13, 2016, 5:48:49 PM12/13/16
to BBEdit Talk, listm...@suddenlink.net
Thanks Chris
Just what I'm after
I'll give it a go
Cheers
Carl

Christopher Stone

unread,
Dec 14, 2016, 12:32:43 AM12/14/16
to BBEdit-Talk
On Dec 13, 2016, at 16:48, Venmore <ven...@gmail.com> wrote:
Thanks Chris … Just what I'm after


Hey Carl,

Great – I hope it works well for you.

After a little more research I found the Apple recommended location for user-installed-java-libraries:

~/Library/Java/Extensions/<your-java-library>

So:

~/Library/Java/Extensions/yuicompressor-2.4.8.jar

--
Best Regards,
Chris

Reply all
Reply to author
Forward
0 new messages