Skip to content

Commit

Permalink
Increase cachability for twitch-embed.html by setting cache-control a…
Browse files Browse the repository at this point in the history
…nd using hash instead of query string.
  • Loading branch information
stefansundin committed Jul 6, 2020
1 parent dc5ad56 commit 0ebaca5
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 4 deletions.
1 change: 1 addition & 0 deletions app.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@

get "/twitch-embed.html" do
content_type :html
cache_control :public, :max_age => 31556926 # cache a long time
SecureHeaders.use_secure_headers_override(request, :twitch_embed)
send_file File.join(settings.views, "twitch-embed.html")
end
Expand Down
2 changes: 1 addition & 1 deletion config/initializers/05-string.rb
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ def embed_html(request=nil)
# https://www.twitch.tv/gamesdonequick
# https://www.twitch.tv/gamesdonequick/video/76877760 (legacy url)
# https://www.twitch.tv/gamesdonequick/v/76877760 (legacy url)
url = "#{request.root_url}/twitch-embed.html?"
url = "#{request.root_url}/twitch-embed.html#"
url += vod_id ? "video=#{vod_id}" : "channel=#{channel_name}"
url += "&time=#{t}" if t
<<~EOF
Expand Down
4 changes: 2 additions & 2 deletions views/twitch-embed.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
<noscript>Please enable JavaScript.</noscript>

<script>
let qs = window.location.search;
let qs = window.location.hash.substr(1);
qs += `&parent=${window.location.hostname}`;
if (document.referrer != "") {
const referrer = new URL(document.referrer);
Expand All @@ -29,7 +29,7 @@
iframe.frameBorder = "0";
iframe.scrolling = "no";
iframe.allowFullscreen = true;
iframe.src = `https://player.twitch.tv/${qs}`;
iframe.src = `https://player.twitch.tv/?${qs}`;
document.body.appendChild(iframe);
</script>
</body>
Expand Down
2 changes: 1 addition & 1 deletion views/twitch.atom.erb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<author><name><%= video["user_name"].esc %></name></author>
<content type="html">
<%= <<~EOF.esc
<iframe width="620" height="378" src="#{request.root_url}/twitch-embed.html?video=#{video["id"]}" frameborder="0" scrolling="no" allowfullscreen referrerpolicy="no-referrer"></iframe>
<iframe width="620" height="378" src="#{request.root_url}/twitch-embed.html#video=#{video["id"]}" frameborder="0" scrolling="no" allowfullscreen referrerpolicy="no-referrer"></iframe>
<p>
<a href="https://player.twitch.tv/?parent=twitch.tv&video=#{video["id"]}" rel="noreferrer">Open embed</a> |
Expand Down

0 comments on commit 0ebaca5

Please sign in to comment.