Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Add CDN support to CompressedCSSandJS

  • Loading branch information...
commit 36e13529af99385995b051b02f48161ab310b3e6 1 parent 16108cd
@obra obra authored
Showing with 6 additions and 2 deletions.
  1. +6 −2 lib/Jifty/Plugin/CompressedCSSandJS.pm
View
8 lib/Jifty/Plugin/CompressedCSSandJS.pm
@@ -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
@@ -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
@@ -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);
@@ -114,6 +116,7 @@ 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>] );
@@ -121,7 +124,7 @@ sub _include_javascript {
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;
@@ -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;
}
Please sign in to comment.
Something went wrong with that request. Please try again.