github
Advanced Search
  • Home
  • Pricing and Signup
  • Explore GitHub
  • Blog
  • Login

jcoglan / packr

  • Admin
  • Watch Unwatch
  • Fork
  • Your Fork
  • Pull Request
  • Download Source
    • 40
    • 0
  • Source
  • Commits
  • Network (0)
  • Issues (0)
  • Downloads (4)
  • Wiki (1)
  • Graphs
  • Branch: master

click here to add a description

click here to add a homepage

  • Branches (3)
    • 1.1
    • 3.1
    • master ✓
  • Tags (4)
    • 3.1.0
    • 1.0.2
    • 1.0.1
    • 1.0.0
Sending Request…
Enable Donations

Pledgie Donations

Once activated, we'll place the following badge in your repository's detail box:
Pledgie_example
This service is courtesy of Pledgie.

Ruby version of Dean Edwards' Packer — Read more

  cancel

http://blog.jcoglan.com/packr/

  cancel
  • Private
  • Read-Only
  • HTTP Read-Only

This URL has Read+Write access

Updating version info, copyright, changelog. 
jcoglan (author)
Sun Feb 22 03:10:47 -0800 2009
commit  5896f94a2240f15f793f2dfdd35282a5b90f595e
tree    f79b4b2f9d934ac89ca2aa9cfe833eae9be8bfea
parent  f6fe1717657415aafdbb7e54c93bca0acef7bcc3
packr /
name age
history
message
file History.txt Sun Feb 22 03:10:47 -0800 2009 Updating version info, copyright, changelog. [jcoglan]
file Manifest.txt Thu Aug 28 12:29:20 -0700 2008 Fixing variable protection and private variable... [jcoglan]
file README.txt Sat Feb 21 16:12:46 -0800 2009 Adding info on 'protect' option to README. [jcoglan]
file Rakefile Sun Jul 13 09:54:38 -0700 2008 This is not a Rails plugin anymore, only a gem.... [jcoglan]
directory bin/ Thu Jul 17 05:09:06 -0700 2008 Refactoring variable protection. Names are pass... [jcoglan]
directory lib/ Sun Feb 22 03:10:47 -0800 2009 Updating version info, copyright, changelog. [jcoglan]
directory test/ Fri Nov 14 04:17:16 -0800 2008 Fixing conditional comments bug in Minifier. [jcoglan]
README.txt
= PackR

* http://github.com/jcoglan/packr
* http://dean.edwards.name/packer/
* http://base2.googlecode.com

== Description

PackR is a Ruby version of Dean Edwards' JavaScript compressor.

== Features

* Whitespace and comment removal
* Compression of local variable names
* Compression and obfuscation of 'private' (_underscored) identifiers
* Base-62 encoding

== Synopsis

To call from within a Ruby program:

  require 'rubygems'
  require 'packr'
  
  code = File.read('my_script.js')
  compressed = Packr.pack(code)
  File.open('my_script.min.js', 'wb') { |f| f.write(compressed) }

This method takes a number of options to control compression, for example:

  compressed = Packr.pack(code, :shrink_vars => true, :base62 => true)

The full list of available options is:

* <tt>:shrink_vars</tt> -- set to +true+ to compress local variable names
* <tt>:private</tt> -- set to +true+ to obfuscate 'private' identifiers, i.e.
  names beginning with a single underscore
* <tt>:base62</tt> -- encode the program using base 62
* <tt>:protect</tt> -- an array of variable names to protect from compression, e.g.

  compressed = Packr.pack(code, :shrink_vars => true,
                                :protect => %w[$super self])

To call from the command line (use <tt>packr --help</tt> to see available options):

  packr my_script.js > my_script.min.js
  
== Notes

This program is not a JavaScript parser, and rewrites your files using regular
expressions. Be sure to include semicolons and braces everywhere they are required
so that your program will work correctly when packed down to a single line.

By far the most efficient way to serve JavaScript over the web is to use PackR
with the --shrink-vars flag, combined with gzip compression. If you don't have access
to your server config to set up mod_deflate, you can generate gzip files using
(on Unix-like systems):

  packr -s my-file.js | gzip > my-file.js.gz
  
You can then get Apache to serve the files by putting this in your .htaccess file:

  AddEncoding gzip .gz
  RewriteCond %{HTTP:Accept-encoding} gzip
  RewriteCond %{HTTP_USER_AGENT} !Safari
  RewriteCond %{REQUEST_FILENAME}.gz -f
  RewriteRule ^(.*)$ $1.gz [QSA,L]

If you really cannot serve gzip files, use the --base62 option to further compress
your code. This mode is at its best when compressing large files with many repeated
tokens.

The --private option can be used to stop other programs calling private methods
in your code by renaming anything beginning with a single underscore. Beware that
you should not use this if the generated file contains 'private' methods that need
to be accessible by other files. Also know that all the files that access any
particular private method must be compressed together so they all get the same
rewritten name for the private method.

== Requirements

* Rubygems
* Oyster (installed automatically)

== Installation

  sudo gem install packr -y

== License

(The MIT License)

Copyright (c) 2004-2009 Dean Edwards, James Coglan

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
'Software'), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Blog | Support | Training | Contact | API | Status | Twitter | Help | Security
© 2010 GitHub Inc. All rights reserved. | Terms of Service | Privacy Policy
Powered by the Dedicated Servers and
Cloud Computing of Rackspace Hosting®
Dedicated Server