Tech Note: A BBEdit Text Filter to Minify Javascript With Google Closure Compiler

Maximum shrinkage
LGF • Views: 35,875

BBEdit is the pinnacle of text editors for Mac OS; it is the El Supremo in the room at the top of the stairs. I’ve been using it on an almost daily basis for more years than I like to think about, and it just keeps getting better.

One of BBEdit’s great features: “Text Filters” that let you write a script or short program in almost any language, and have it work on the contents of the current text document. Today I searched in vain for an already-written text filter that would call the Google Closure Compiler to “minify” Javascript code, and ended up just writing one myself, and I’m passing it on in case someone else out there might find it useful.

To use this, you have to first install the Closure Compiler Java app on your system, which isn’t difficult:

  • Download the ZIP file and expand it. (The decompression should happen automatically after downloading; if not, double click the ZIP file.)
  • In the Finder’s Go menu, click “Go to Folder…” and enter /usr/local/lib in the dialog box. This opens a desktop window showing that folder.
  • Copy the file compiler.jar from the folder compiler-latest to this new window. Because it’s in a system directory, you’ll probably be asked to enter your login password before the copy will proceed.

That’s it — the Closure Compiler is ready to go. Unless you’ve removed it, Java is already installed in Mac OS, so you shouldn’t need to do anything else.

Now for the Text Filter. In BBEdit, open a new window and and enter this short and simple Bash shell script:

#!/bin/bash

echo -n $(java -jar /usr/local/lib/compiler.jar --compilation_level SIMPLE_OPTIMIZATIONS <&0)

This script needs to be placed in:

~/Library/Application Support/BBEdit/Text Filters

Easiest way to get it there is to first save it to the Desktop, as Closure compiler.sh, then use the Finder’s Go->Go to Folder menu again to open the Text Filters folder, and move the file in. (This time, you shouldn’t need to enter a password because it’s your own Library folder.)

Now you’re ready to minify some Javascript. Open a BBEdit window with some code, then go to Text->Text Filters, and choose “Closure Compiler.” Wait a few seconds and BAM! All that code is suddenly compressed with the best minifier available. We’re talking maximum shrinkage here.

If you mark a selection before using the text filter, just that section will be minified. If you’re feeling adventurous, you can set the compilation_level option in the text filter to “ADVANCED_OPTIMIZATIONS,” but this won’t work with all code; there are some strict requirements. Check the Closure Compiler docs for more on that.

Jump to bottom

38 comments
1 wrenchwench  Mon, May 13, 2013 2:58:02pm
2 Charles Johnson  Mon, May 13, 2013 2:58:29pm

re: #1 wrenchwench

Where’s the part about ‘You ignoramouses can haz open thread now’?

I figure that’s understood.

3 wrenchwench  Mon, May 13, 2013 2:59:13pm

re: #2 Charles Johnson

I figure that’s understood.

And only that.

4 klys  Mon, May 13, 2013 2:59:45pm

My talk for the conference in June is not writing itself. :(

5 wrenchwench  Mon, May 13, 2013 3:00:50pm

re: #4 klys

My talk for the conference in June is not writing itself. :(

‘Minds me of this.

6 klys  Mon, May 13, 2013 3:01:46pm

re: #5 wrenchwench

‘Minds me of this.

It would help if there was something more to this talk than: the data I didn’t really do anything with. But there’s not.

8 klys  Mon, May 13, 2013 3:04:27pm

If you check out the geyser cam, Beehive is about to go.

9 Lidane  Mon, May 13, 2013 3:07:29pm

re: #7 NJDhockeyfan

Burger built in lab costs $325,000 to produce, ‘tastes reasonably good’

If I wanted a burger built in a lab, I’d go to McDonald’s. =P

10 GeneJockey  Mon, May 13, 2013 3:08:29pm

re: #7 NJDhockeyfan

Years ago, my boss, a Post Doc, and I were all putting in really long hours trying to get something submitted to Nature before Christmas (Submitted 24 December, 1984), and this led us to a number of silly conversations. One involved the potential origin of Chicken McNuggets, since there’s no obvious place they came from. We imagined using, for example, a muscle-derived tumor line to grow McNuggets in the lab - Sarcoma McNuggets

We figured the name would have to be changed.

11 NJDhockeyfan  Mon, May 13, 2013 3:08:32pm

re: #9 Lidane

If I wanted a burger built in a lab, I’d go to McDonald’s. =P

It’s definitely cheaper at McD’s

12 darthstar  Mon, May 13, 2013 3:09:58pm

re: #8 klys

If you check out the geyser cam, Beehive is about to go.

Cool. I haven’t been there since ‘88.

13 recusancy  Mon, May 13, 2013 3:10:42pm

I’m sorry but the pinnacle of text editors is Sublime Text.

14 klys  Mon, May 13, 2013 3:10:56pm

re: #12 darthstar

Cool. I haven’t been there since ‘88.

One of my favorite places on Earth. Added bonus, Old Faithful is starting.

15 Eclectic Cyborg  Mon, May 13, 2013 3:11:21pm

Had a lot on my mind regarding the recent immigration related developments.
I finally got around to paging my thoughts.

16 darthstar  Mon, May 13, 2013 3:12:33pm

re: #8 klys

If you check out the geyser cam, Beehive is about to go.

That was well worth the five minutes I had to wait. Thanks.

17 darthstar  Mon, May 13, 2013 3:12:53pm

re: #13 recusancy

I’m sorry but the pinnacle of text editors is Sublime Text.

Yeah…I like Sublime as well.

18 NJDhockeyfan  Mon, May 13, 2013 3:13:16pm
19 klys  Mon, May 13, 2013 3:14:07pm

re: #16 darthstar

That was well worth the five minutes I had to wait. Thanks.

The one in front was Old Faithful. Beehive hasn’t gone yet, is the one in back where all the people are lined up on the boardwalk. :)

20 thedopefishlives  Mon, May 13, 2013 3:15:02pm

re: #13 recusancy

I’m sorry but the pinnacle of text editors is Sublime Text.

Wow, whatever happened to good old-fashioned vim.

*ducks*

21 darthstar  Mon, May 13, 2013 3:15:27pm

re: #19 klys

The one in front was Old Faithful. Beehive hasn’t gone yet, is the one in back where all the people are lined up on the boardwalk. :)

Yep…I remember them well. Definitely need to plan a return trip some day. Oh, and I’m glad they didn’t cut off the geysers with the Sequester.

22 recusancy  Mon, May 13, 2013 3:16:43pm

re: #20 thedopefishlives

Wow, whatever happened to good old-fashioned vim.

*ducks*

I’m not that hardcore of a nerd. Too big of a muscle memory learning curve.

23 thedopefishlives  Mon, May 13, 2013 3:17:33pm

re: #22 recusancy

I’m not that hardcore of a nerd. Too big of a muscle memory learning curve.

I was lucky. I had professional training. Of course, even that wasn’t enough to be able to teach me Emacs.

24 MichaelJ  Mon, May 13, 2013 3:17:34pm

Side note - Macs that shipped with OS X 10.7 or higher no longer have Java installed by default.

25 klys  Mon, May 13, 2013 3:17:40pm

re: #21 darthstar

Yep…I remember them well. Definitely need to plan a return trip some day. Oh, and I’m glad they didn’t cut off the geysers with the Sequester.

Hahaha. I try not to assume that everyone is as obsessed with and knows the various geysers like I do.

We were there last summer (that’s when my Beehive photo was taken - first eruption of that I’d seen). I would half-like to go again this year but I think my husband would be sad. Fan and Mortar continues to taunt me - it’s been at the right point of the cycle for eruption both trips but nothing has happened, despite spending a couple hours watching each visit (or all day one day, last year).

I can easily spend weeks there and not get bored.

26 lawhawk  Mon, May 13, 2013 3:25:30pm

re: #12 darthstar

I can’t wait to get back. It’s an amazing place.

27 timwayne  Mon, May 13, 2013 3:26:29pm

Hi Charles,

I’ve been using BBEdit since the late 1996, I think. Mostly, I use it to strip gremlins out of code, but occasionally, I use it for bigger stuff.

I have need of a script and I don’t know how to do it.

A few times a day, I need to write a plain-text email where I quote the sender. Because it must be plain-text, and I am quoting from an HTML-formatted source, I have to count out to 60 characters, then hit the carriage return, then put a > on the next line, followed by a couple of spaces. To wit:

> This is so the text I am quoting looks like quoted text. Like this :-)

Is it possible to write a script that will do this counting-out-and-inserting for me? How would I find out how to do this?

28 Charles Johnson  Mon, May 13, 2013 3:27:34pm

re: #24 MichaelJ

Side note - Macs that shipped with OS X 10.7 or higher no longer have Java installed by default.

Actually, I believe they only removed the Java plugin for Safari. Java itself is still installed as part of the Unix system. I didn’t have to install Java and I’m running 10.8.3. You can check it on the command line in Terminal - if “man java” brings up the help page, then Java’s installed.

Java is only a security issue when it’s run in a browser - that’s why Apple nuked the plugin.

29 lawhawk  Mon, May 13, 2013 3:28:48pm

re: #25 klys

Wish I could be there for when Steamboat does a major eruption, but that’s so infrequent that it’d be like hitting the jackpot. It was doing a minor eruption 25-50 feet or so, and you got the sense of just how powerful that can be.

30 darthstar  Mon, May 13, 2013 3:29:47pm
31 Charles Johnson  Mon, May 13, 2013 3:30:15pm

re: #27 timwayne

I think I’d use Keyboard Maestro to automate that, myself, instead of writing a script. Have you tried using the “Start Recording” function in BBEdit’s Script menu? You might be able to get it done with that.

32 William of Orange  Mon, May 13, 2013 3:34:27pm

Charles,

Could you also put a kind of international filter on the pop-ups? If I was American I sure would be a Democrat but as a foreigner I cannot insert an American zip code to any of the pop-ups.

In other words, for Non-Americans the pop-ups have no use.

33 klys  Mon, May 13, 2013 3:36:38pm

re: #29 lawhawk

Wish I could be there for when Steamboat does a major eruption, but that’s so infrequent that it’d be like hitting the jackpot. It was doing a minor eruption 25-50 feet or so, and you got the sense of just how powerful that can be.

Steamboat would be *fantastic*, or Giant, or Giantess - I have vague hopes that if Giantess does go, I can see it on the webcam. But for the most part I only stalk the ones that have an *actual* hope of going off while I’m there.

I netted a whole bunch of new ones this last trip - Riverside, Beehive, Lonestar, Lion. Penta was gurgling and looked to go, but didn’t. Fan and Mortar delighted in producing junk cycles.

And that was just 3 days worth of watching. What I wouldn’t give to spend a whole week or three.

My copy of The Geysers of Yellowstone is becoming so battered, I am tempted to get a second copy. Also helpful for when the husband steals it.

34 lawhawk  Mon, May 13, 2013 3:37:46pm

Popular psychologist and TV personality Joyce Brothers has passed away at 85.

Also, noted political science/international relations theorist Kenneth Waltz, who established the neorealist school, passed away today as well.

RIP

35 Lidane  Mon, May 13, 2013 3:44:04pm
36 William Barnett-Lewis  Mon, May 13, 2013 3:53:04pm

re: #20 thedopefishlives

Wow, whatever happened to good old-fashioned vim.

*ducks*

VI only exists to edit the EMACS Makefile … (G,D & R)

37 Backwoods_Sleuth  Mon, May 13, 2013 4:32:36pm

shop kittens (now house kittens) are two weeks old today…

kitteh sez ohai!

38 klys  Mon, May 13, 2013 4:33:13pm

re: #37 Backwoods_Sleuth

shop kittens (now house kittens) are two weeks old today…

kitteh sez ohai!

Kittehs!


This article has been archived.
Comments are closed.

Jump to top

Create a PageThis is the LGF Pages posting bookmarklet. To use it, drag this button to your browser's bookmark bar, and title it 'LGF Pages' (or whatever you like). Then browse to a site you want to post, select some text on the page to use for a quote, click the bookmarklet, and the Pages posting window will appear with the title, text, and any embedded video or audio files already filled in, ready to go.
Or... you can just click this button to open the Pages posting window right away.
Last updated: 2023-04-04 11:11 am PDT
LGF User's Guide RSS Feeds

Help support Little Green Footballs!

Subscribe now for ad-free access!Register and sign in to a free LGF account before subscribing, and your ad-free access will be automatically enabled.

Donate with
PayPal
Cash.app
Recent PagesClick to refresh
Once Praised, the Settlement to Help Sickened BP Oil Spill Workers Leaves Most With Nearly Nothing When a deadly explosion destroyed BP’s Deepwater Horizon drilling rig in the Gulf of Mexico, 134 million gallons of crude erupted into the sea over the next three months — and tens of thousands of ordinary people were hired ...
Cheechako
4 hours ago
Views: 52 • Comments: 0 • Rating: 0
Texas County at Center of Border Fight Is Overwhelmed by Migrant Deaths EAGLE PASS, Tex. - The undertaker lighted a cigarette and held it between his latex-gloved fingers as he stood over the bloated body bag lying in the bed of his battered pickup truck. The woman had been fished out ...
Cheechako
4 days ago
Views: 161 • Comments: 0 • Rating: 1