Skip to content

Commit

Permalink
Add CDN support to CompressedCSSandJS
Browse files Browse the repository at this point in the history
  • Loading branch information
obra committed May 7, 2012
1 parent 16108cd commit 36e1352
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions lib/Jifty/Plugin/CompressedCSSandJS.pm
Expand Up @@ -24,6 +24,7 @@ Jifty::Plugin::CompressedCSSandJS - Compression of CSS and javascript files
js: 1
css: 1
jsmin: /path/to/jsmin
cdn_url_prefix: https://app.ssl.a.fastly.net
skipped_js:
- complex.js
Expand All @@ -45,7 +46,7 @@ skipped_js is a list of js that you don't want to compress for some reason.
=cut

__PACKAGE__->mk_accessors(qw(css js jsmin skipped_js external_publish));
__PACKAGE__->mk_accessors(qw(css js jsmin skipped_js cdn_url_prefix external_publish));

=head2 init
Expand All @@ -64,6 +65,7 @@ sub init {
$self->js( $opt{js} );
$self->jsmin( $opt{jsmin} );
$self->external_publish( $opt{external_publish} );
$self->cdn_url_prefix($opt{cdn_url_prefix} ||'');
if ($self->external_publish and not Jifty::CAS->backend("ccjs")->durable) {
$self->log->warn("External publishing does not work with non-durable CAS stores; disabling");
$self->external_publish(0);
Expand Down Expand Up @@ -114,14 +116,15 @@ sub _include_javascript {
$self->generate_javascript unless $self->external_publish;
Jifty->web->out(
qq[<script type="text/javascript" src="]
. $self->cdn_url_prefix()
. Jifty::CAS->uri("ccjs","js-all")
. qq[.js"></script>] );

my $skipped_js = $self->skipped_js;
if ( $self->skipped_js ) {
for my $file ( @{ $self->skipped_js } ) {
Jifty->web->out(
qq{<script type="text/javascript" src="/static/js/$file" /> });
qq{<script type="text/javascript" src="'}.$self->cdn_url_prefix.qq{ '/static/js/$file" /> });
}
}
return 0;
Expand All @@ -132,6 +135,7 @@ sub _include_css {
$self->generate_css unless $self->external_publish;
Jifty->web->out(
qq{<link rel="stylesheet" type="text/css" href="}
. $self->cdn_url_prefix()
. Jifty::CAS->uri('ccjs', 'css-all').'.css" />');
return 0;
}
Expand Down

0 comments on commit 36e1352

Please sign in to comment.