[Jifty-commit] jifty branch, js-refactor, updated. 72cb1ffe8110ff103022c40c76a0c5a093bc17f6

Jifty commits jifty-commit at lists.jifty.org
Thu Jan 14 21:48:34 EST 2010


The branch, js-refactor has been updated
       via  72cb1ffe8110ff103022c40c76a0c5a093bc17f6 (commit)
      from  034ea91d49db3a079f4d7791266e64141bd7c71b (commit)

Summary of changes:
 lib/Jifty/Plugin/CompressedCSSandJS.pm |   41 +++++++++++++++++++++----------
 1 files changed, 28 insertions(+), 13 deletions(-)

- Log -----------------------------------------------------------------
commit 72cb1ffe8110ff103022c40c76a0c5a093bc17f6
Author: Thomas Sibley <trs at bestpractical.com>
Date:   Thu Jan 14 21:48:00 2010 -0500

    Support generating CSS/JS at start rather than the first request

diff --git a/lib/Jifty/Plugin/CompressedCSSandJS.pm b/lib/Jifty/Plugin/CompressedCSSandJS.pm
index aafcb69..1a8d190 100644
--- a/lib/Jifty/Plugin/CompressedCSSandJS.pm
+++ b/lib/Jifty/Plugin/CompressedCSSandJS.pm
@@ -24,6 +24,7 @@ Jifty::Plugin::CompressedCSSandJS - Compression of CSS and javascript files
         gzip: 1
         skipped_js:
             - complex.js
+        generate_early: 1
 
 
 =head1 DESCRIPTION
@@ -45,9 +46,14 @@ indicates it supports that feature.
 
 skipped_js is a list of js that you don't want to compress for some reason.
 
+generate_early tells the plugin to compress the CSS and JS at process start
+rather than on the first request.  This can save time, especially if your
+JS minifier is slow, for the poor sucker who makes the first request.  Enabled
+by default.
+
 =cut
 
-__PACKAGE__->mk_accessors(qw(css js jsmin cdn gzip_enabled skipped_js));
+__PACKAGE__->mk_accessors(qw(css js jsmin cdn gzip_enabled skipped_js generate_early));
 
 =head2 init
 
@@ -67,18 +73,27 @@ sub init {
     $self->js( $opt{js} );
     $self->jsmin( $opt{jsmin} );
     $self->cdn( $opt{cdn} || '');
+    $self->generate_early( exists $opt{generate_early} ? $opt{generate_early} : 1 );
+
+    if ( $self->js_enabled ) {
+        Jifty::Web->add_trigger(
+            name      => 'include_javascript',
+            callback  => sub { $self->_include_javascript(@_) },
+            abortable => 1,
+        );
+        Jifty->add_trigger( post_init => sub { $self->_generate_javascript })
+            if $self->generate_early;
+    }
 
-    Jifty::Web->add_trigger(
-        name      => 'include_javascript',
-        callback  => sub { $self->_include_javascript(@_) },
-        abortable => 1,
-    ) if $self->js_enabled;
-
-    Jifty::Web->add_trigger(
-        name => 'include_css',
-        callback => sub { $self->_include_css(@_) },
-        abortable => 1,
-    ) if $self->css_enabled;
+    if ( $self->css_enabled ) {
+        Jifty::Web->add_trigger(
+            name => 'include_css',
+            callback => sub { $self->_include_css(@_) },
+            abortable => 1,
+        );
+        Jifty->add_trigger( post_init => sub { $self->generate_css })
+            if $self->generate_early;
+    }
 }
 
 =head2 js_enabled

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


More information about the Jifty-commit mailing list