Skip to content

Instantly share code, notes, and snippets.

@tomfuertes
Last active November 10, 2024 20:51
Show Gist options
  • Select an option

  • Save tomfuertes/6978b594d34038d763a9ee3c4d4c9b14 to your computer and use it in GitHub Desktop.

Select an option

Save tomfuertes/6978b594d34038d763a9ee3c4d4c9b14 to your computer and use it in GitHub Desktop.

Revisions

  1. tomfuertes revised this gist May 6, 2016. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion http2-server-push.rb
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,6 @@
    class ApplicationController < ActionController::Base

    after_filter :server_push_headers
    after_action :server_push_headers # https://twitter.com/connorjshea/status/728472354385317888

    def server_push_headers
    # CLoudflare HTTP2 Server Push: https://blog.cloudflare.com/announcing-support-for-http-2-server-push-2/
  2. tomfuertes revised this gist May 6, 2016. 1 changed file with 6 additions and 0 deletions.
    6 changes: 6 additions & 0 deletions http2-server-push.rb
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,7 @@
    class ApplicationController < ActionController::Base

    after_filter :server_push_headers

    def server_push_headers
    # CLoudflare HTTP2 Server Push: https://blog.cloudflare.com/announcing-support-for-http-2-server-push-2/
    if request.format.html? # only on html pages
    @@ -17,3 +21,5 @@ def server_push_headers
    end
    end
    end

    end
  3. tomfuertes created this gist May 6, 2016.
    19 changes: 19 additions & 0 deletions http2-server-push.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,19 @@
    def server_push_headers
    # CLoudflare HTTP2 Server Push: https://blog.cloudflare.com/announcing-support-for-http-2-server-push-2/
    if request.format.html? # only on html pages
    layout = self.send(:_layout) # with the right layout
    if layout == "main" || layout == "speaker" || layout == "admin"
    assets = [
    "<#{view_context.asset_path('application.css')}>; rel=preload; as=style",
    "<#{view_context.asset_path('application.js')}>; rel=preload; as=script",
    "<#{view_context.asset_path("twitter/bootstrap/glyphicons-halflings.png")}>; rel=preload; as=image",
    "<#{view_context.asset_path("site/#{site.code}/logo.png")}>; rel=preload; as=image",
    ]
    assets.push([
    "<#{view_context.asset_path("ppc/check.png")}>; rel=preload; as=image",
    "<#{view_context.asset_path("icons/ratings/star-off.png")}>; rel=preload; as=image",
    ]) if params[:controller] == 'speakers' && params[:action] == 'show'
    response.headers['Link'] = assets
    end
    end
    end