Skip to content

Commit

Permalink
Merge pull request #3428 from alphagov/remove-apple-touch-icon-redirects
Browse files Browse the repository at this point in the history
Remove custom apple touch icons and redirects in static
  • Loading branch information
MartinJJones committed Sep 19, 2024
2 parents f8560a0 + f37d969 commit a1daebe
Show file tree
Hide file tree
Showing 8 changed files with 19 additions and 161 deletions.
Binary file removed app/assets/images/apple-touch-icon-152x152.png
Binary file not shown.
Binary file removed app/assets/images/apple-touch-icon-167x167.png
Binary file not shown.
Binary file removed app/assets/images/apple-touch-icon-180x180.png
Binary file not shown.
Binary file removed app/assets/images/apple-touch-icon.png
Binary file not shown.
10 changes: 2 additions & 8 deletions app/controllers/icon_redirects_controller.rb
Original file line number Diff line number Diff line change
@@ -1,14 +1,8 @@
class IconRedirectsController < ApplicationController
before_action { expires_in(1.day, public: true) }

def show
redirect_to(view_context.asset_path(request.path.to_s[1..]),
status: :moved_permanently,
allow_other_host: true)
end

def apple_old_size_icon
redirect_to(view_context.asset_path("apple-touch-icon.png"),
def show_favicon
redirect_to(view_context.asset_path("favicon.ico"),
status: :moved_permanently,
allow_other_host: true)
end
Expand Down
26 changes: 2 additions & 24 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,28 +15,6 @@
get "/templates/:template.html.erb", to: "root#template"
end

# Icon redirects
get "/favicon.ico", to: "icon_redirects#show"
get "/apple-touch-icon.png", to: "icon_redirects#show"
get "/apple-touch-icon-180x180.png", to: "icon_redirects#show"
get "/apple-touch-icon-167x167.png", to: "icon_redirects#show"
get "/apple-touch-icon-152x152.png", to: "icon_redirects#show"

# Old devices with old OSs may still request these old image sizes
# They should receive a working image.
# It's acceptable to send them a higher resolution image which they will downscale.
# https://mathiasbynens.be/notes/touch-icons
get "/apple-touch-icon-120x120.png", to: "icon_redirects#apple_old_size_icon"
get "/apple-touch-icon-76x76.png", to: "icon_redirects#apple_old_size_icon"
get "/apple-touch-icon-60x60.png", to: "icon_redirects#apple_old_size_icon"
get "/apple-touch-icon-precomposed.png", to: "icon_redirects#apple_old_size_icon"
get "/apple-touch-icon-114x114-precomposed.png", to: "icon_redirects#apple_old_size_icon"
get "/apple-touch-icon-120x120-precomposed.png", to: "icon_redirects#apple_old_size_icon"
get "/apple-touch-icon-144x144-precomposed.png", to: "icon_redirects#apple_old_size_icon"
get "/apple-touch-icon-152x152-precomposed.png", to: "icon_redirects#apple_old_size_icon"
get "/apple-touch-icon-176x176-precomposed.png", to: "icon_redirects#apple_old_size_icon"
get "/apple-touch-icon-180x180-precomposed.png", to: "icon_redirects#apple_old_size_icon"
get "/apple-touch-icon-57x57-precomposed.png", to: "icon_redirects#apple_old_size_icon"
get "/apple-touch-icon-72x72-precomposed.png", to: "icon_redirects#apple_old_size_icon"
get "/apple-touch-icon-76x76-precomposed.png", to: "icon_redirects#apple_old_size_icon"
# Favicon redirect
get "/favicon.ico", to: "icon_redirects#show_favicon"
end
90 changes: 0 additions & 90 deletions lib/tasks/publishing_api.rake
Original file line number Diff line number Diff line change
Expand Up @@ -5,96 +5,6 @@ ROUTES = [
title: "Favicon",
description: "The favicon is the image displayed in locations such as the browser tabs.",
},
{
base_path: "/apple-touch-icon.png",
content_id: "cdc36458-74d4-42a7-86c8-221e03877dfc",
title: "Crest for Apple iOS bookmarks",
description: "Used by iOS when saving GOV.UK as a shortcut icon.",
},
{
base_path: "/apple-touch-icon-144x144.png",
content_id: "a18912cb-94ff-46a0-b9a3-5f707b0dca2f",
title: "Crest for Apple iOS bookmarks 144px by 144px",
description: "Used by iOS when saving GOV.UK as a shortcut icon.",
},
{
base_path: "/apple-touch-icon-114x114.png",
content_id: "d8a8b79a-b056-4f87-bb48-47566645f358",
title: "Crest for Apple iOS bookmarks 114px by 114px",
description: "Used by iOS when saving GOV.UK as a shortcut icon.",
},
{
base_path: "/apple-touch-icon-72x72.png",
content_id: "98fc34ab-b620-4bd4-bc8a-d4db63960f4f",
title: "Crest for Apple iOS bookmarks 72px by 72px",
description: "Used by iOS when saving GOV.UK as a shortcut icon.",
},
{
base_path: "/apple-touch-icon-57x57.png",
content_id: "c7de1c80-f278-49c4-84cd-a8ff53149ab6",
title: "Crest for Apple iOS bookmarks 57px by 57px",
description: "Used by iOS when saving GOV.UK as a shortcut icon.",
},
{
base_path: "/apple-touch-icon-precomposed.png",
content_id: "d8c1618b-ad27-42f3-a7cd-b11f4b90a15e",
title: "Crest for Apple iOS bookmarks",
description: "Used by iOS when saving GOV.UK as a shortcut icon.",
},
{
base_path: "/apple-touch-icon-114x114-precomposed.png",
content_id: "c15ee6fd-fb3a-45ab-b9e1-0efe1a8a6c2e",
title: "Crest for Apple iOS bookmarks",
description: "Used by iOS when saving GOV.UK as a shortcut icon.",
},
{
base_path: "/apple-touch-icon-120x120-precomposed.png",
content_id: "2e676337-94f3-4f4f-8501-83a1c7813bf8",
title: "Crest for Apple iOS bookmarks",
description: "Used by iOS when saving GOV.UK as a shortcut icon.",
},
{
base_path: "/apple-touch-icon-144x144-precomposed.png",
content_id: "5fd9d11e-997a-4850-ad69-a43a3aec8a9f",
title: "Crest for Apple iOS bookmarks",
description: "Used by iOS when saving GOV.UK as a shortcut icon.",
},
{
base_path: "/apple-touch-icon-152x152-precomposed.png",
content_id: "39541207-fdce-4415-8498-42477fce4b58",
title: "Crest for Apple iOS bookmarks",
description: "Used by iOS when saving GOV.UK as a shortcut icon.",
},
{
base_path: "/apple-touch-icon-176x176-precomposed.png",
content_id: "96833c45-64e2-4bdb-af43-90a96be2a1a3",
title: "Crest for Apple iOS bookmarks",
description: "Used by iOS when saving GOV.UK as a shortcut icon.",
},
{
base_path: "/apple-touch-icon-180x180-precomposed.png",
content_id: "db853854-42a6-49ce-95c5-0b41b4bed921",
title: "Crest for Apple iOS bookmarks",
description: "Used by iOS when saving GOV.UK as a shortcut icon.",
},
{
base_path: "/apple-touch-icon-57x57-precomposed.png",
content_id: "ead323b2-80e0-494f-8b1d-f7f998b9267c",
title: "Crest for Apple iOS bookmarks",
description: "Used by iOS when saving GOV.UK as a shortcut icon.",
},
{
base_path: "/apple-touch-icon-72x72-precomposed.png",
content_id: "4068ca41-f6b1-48d5-a19d-3ea85be49434",
title: "Crest for Apple iOS bookmarks",
description: "Used by iOS when saving GOV.UK as a shortcut icon.",
},
{
base_path: "/apple-touch-icon-76x76-precomposed.png",
content_id: "0526a59d-c9f8-4d44-8649-e54d532a0b35",
title: "Crest for Apple iOS bookmarks",
description: "Used by iOS when saving GOV.UK as a shortcut icon.",
},
].freeze

namespace :publishing_api do
Expand Down
54 changes: 15 additions & 39 deletions test/integration/icon_redirects_test.rb
Original file line number Diff line number Diff line change
@@ -1,47 +1,23 @@
require_relative "../integration_test_helper"

class IconRedirectsTest < ActionDispatch::IntegrationTest
[
"favicon.ico",
"apple-touch-icon.png",
"apple-touch-icon-180x180.png",
"apple-touch-icon-167x167.png",
"apple-touch-icon-152x152.png",
].each do |file|
should "redirect #{file} to the asset path" do
get "/#{file}"
assert_equal 301, last_response.status
assert_equal last_response.headers["Cache-Control"], "max-age=86400, public"
# In development and test mode the asset pipeline doesn't add the hashes to the URLs
assert_equal "http://example.org/assets/static/#{file}", last_response.location
end

# TODO: check if this test is required and raise an issue for it
# should "redirect #{file} to a location that exists" do
# get "/assets/static/#{file}"
# assert_equal 200, last_response.status
# assert last_response.body.size > 100
# end
should "redirect `favicon.ico` to the asset path" do
get "/favicon.ico"
assert_equal 301, last_response.status
assert_equal last_response.headers["Cache-Control"], "max-age=86400, public"
# In development and test mode the asset pipeline doesn't add the hashes to the URLs
assert_equal "http://example.org/assets/static/favicon.ico", last_response.location
end

should "ignore query string when redirecting #{file}" do
get "/#{file}?foo=bar"
assert_equal 301, last_response.status
assert_equal "http://example.org/assets/static/#{file}", last_response.location
end
should "redirect `favicon.ico` to a location that exists" do
get "/assets/static/favicon.ico"
assert_equal 200, last_response.status
assert last_response.body.size > 100
end

[
"apple-touch-icon-120x120.png",
"apple-touch-icon-76x76.png",
"apple-touch-icon-60x60.png",
"apple-touch-icon-precomposed.png",
].each do |file|
should "redirect old icon size #{file} to the default apple-touch-icon.png icon" do
get "/#{file}"
assert_equal 301, last_response.status
assert_equal last_response.headers["Cache-Control"], "max-age=86400, public"
# In development and test mode the asset pipeline doesn't add the hashes to the URLs
assert_equal "http://example.org/assets/static/apple-touch-icon.png", last_response.location
end
should "ignore query string when redirecting `favicon.ico`" do
get "/favicon.ico?foo=bar"
assert_equal 301, last_response.status
assert_equal "http://example.org/assets/static/favicon.ico", last_response.location
end
end

0 comments on commit a1daebe

Please sign in to comment.