Skip to content

Commit

Permalink
Item14504: added http/2 push headers
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelDaum committed Sep 25, 2017
1 parent 4030deb commit 4c32e54
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 7 deletions.
4 changes: 3 additions & 1 deletion data/System/PageOptimizerPlugin.txt
Expand Up @@ -69,6 +69,8 @@ the =refresh= url parameter:
%$DEPENDENCIES%

---++ Change History
%TABLE{columnwidths="7em" tablewidth="100%"}%
| 25 Sep 2017: | added http/2 push headers |
| 09 Sep 2016: | improved cache handling, i.e. added a rest handler to purge the cache occasionally |
| 13 Jun 2016: | fixed compatibility with <nop>AngularPlugin/AngularSkin; performance improvements |
| 23 Feb 2015: | remove some bogus non-macros if left over, such as REVISIONS, REVTITLE, REVARG, QUERYPARAMSTRING |
Expand All @@ -86,7 +88,7 @@ the =refresh= url parameter:
%META:FIELD{name="Release" title="Release" value="%25$RELEASE%25"}%
%META:FIELD{name="Description" title="Description" value="%25$SHORTDESCRIPTION%25"}%
%META:FIELD{name="Repository" title="Repository" value="https://github.com/foswiki/%25TOPIC%25"}%
%META:FIELD{name="Copyright" title="Copyright" value="&copy; 2012-2016 Michael Daum http://michaeldaumconsulting.com"}%
%META:FIELD{name="Copyright" title="Copyright" value="&copy; 2012-2017 Michael Daum http://michaeldaumconsulting.com"}%
%META:FIELD{name="License" title="License" value="[[http://www.gnu.org/licenses/gpl.html][GPL (Gnu General Public License)]]"}%
%META:FIELD{name="Home" title="Home" value="Foswiki:Extensions/%25TOPIC%25"}%
%META:FIELD{name="Support" title="Support" value="Foswiki:Support/%25TOPIC%25"}%
6 changes: 3 additions & 3 deletions lib/Foswiki/Plugins/PageOptimizerPlugin.pm
@@ -1,6 +1,6 @@
# Plugin for Foswiki - The Free and Open Source Wiki, http://foswiki.org/
#
# Copyright (C) 2012-2016 Michael Daum http://michaeldaumconsulting.com
# Copyright (C) 2012-2017 Michael Daum http://michaeldaumconsulting.com
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
Expand All @@ -24,8 +24,8 @@ use Digest::MD5 ();
use URI ();
use Compress::Zlib ();

our $VERSION = '2.10';
our $RELEASE = '09 Sep 2016';
our $VERSION = '3.00';
our $RELEASE = '25 Sep 2017';
our $SHORTDESCRIPTION = 'Optimize html markup, as well as js and css';
our $NO_PREFS_IN_TOPIC = 1;
our $core;
Expand Down
15 changes: 13 additions & 2 deletions lib/Foswiki/Plugins/PageOptimizerPlugin/Core.pm
@@ -1,6 +1,6 @@
# Plugin for Foswiki - The Free and Open Source Wiki, http://foswiki.org/
#
# Copyright (C) 2012-2016 Michael Daum http://michaeldaumconsulting.com
# Copyright (C) 2012-2017 Michael Daum http://michaeldaumconsulting.com
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
Expand All @@ -17,6 +17,7 @@ package Foswiki::Plugins::PageOptimizerPlugin::Core;

use strict;
use warnings;
use Foswiki::Plugins();
use Foswiki::Func();
use Foswiki::Plugins::PageOptimizerPlugin ();

Expand Down Expand Up @@ -158,6 +159,11 @@ sub optimizeJavaScript {
# remove the rest
$text =~ s/\0js\0//g;

# add http/2 server push to http header
my $session = $Foswiki::Plugins::SESSION;
my $response = $session->{response};
$response->pushHeader('Link', '<'.$cacheUrl.'>; rel=preload; as=script' );

return $text;
}

Expand Down Expand Up @@ -216,9 +222,14 @@ sub optimizeStylesheets {

my $classes = join(" ", sort keys %classes);

$text =~ s/\0css\0/<link class='$classes' rel='stylesheet' href='$cacheUrl' media='all' \/>/;
$text =~ s/\0css\0/<link rel='stylesheet' href='$cacheUrl' class='$classes' media='all' \/>/;
$text =~ s/\0css\0//g;

# add http/2 server push to http header
my $session = $Foswiki::Plugins::SESSION;
my $response = $session->{response};
$response->pushHeader('Link', '<'.$cacheUrl.'>; rel=preload; as=style' );

return $text;
}

Expand Down
1 change: 1 addition & 0 deletions lib/Foswiki/Plugins/PageOptimizerPlugin/MANIFEST
@@ -1,3 +1,4 @@
!noci
data/System/PageOptimizerPlugin.txt 0644
lib/Foswiki/Plugins/PageOptimizerPlugin/Config.spec 0644
lib/Foswiki/Plugins/PageOptimizerPlugin/Core.pm 0644
Expand Down
2 changes: 1 addition & 1 deletion lib/Foswiki/Plugins/PageOptimizerPlugin/Stats.pm
@@ -1,6 +1,6 @@
# Plugin for Foswiki - The Free and Open Source Wiki, http://foswiki.org/
#
# Copyright (C) 2012-2016 Michael Daum http://michaeldaumconsulting.com
# Copyright (C) 2012-2017 Michael Daum http://michaeldaumconsulting.com
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
Expand Down

0 comments on commit 4c32e54

Please sign in to comment.