Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
レスポンシブから逆戻り!?Webサービスのマルチデバイス対応方法 / Multi-Device...
Search
shimataro
November 28, 2017
Technology
310
1
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
レスポンシブから逆戻り!?Webサービスのマルチデバイス対応方法 / Multi-Device Support Method for Web Services
東京Node学園祭2017の発表資料です
http://nodefest.jp/2017/
shimataro
November 28, 2017
More Decks by shimataro
See All by shimataro
作って理解するPromise / Let's try implementing Promise
shimataro
0
65
Single Executable Applicationsについて / About Single Executable Applications
shimataro
0
2.1k
パッケージ開発者の苦悩 -JavaScriptランタイム群雄割拠- / distress of package developer
shimataro
0
880
An introduction to Node.js
shimataro
0
330
KFDのススメ / About KFD
shimataro
3
870
Node.js v12のES Modules / ES Modules on NodeJS v12
shimataro
1
1.2k
おまいらちゃんとリソース解放してますか / Remember to close resources!
shimataro
2
1.3k
CJSとESMとnpmパッケージ / CommonJS and ES Modules and npm package
shimataro
0
860
BigInt あれこれ / overview about BigInt
shimataro
0
990
Other Decks in Technology
See All in Technology
omasushiというライブラリを作った
polidog
PRO
0
190
Where Is JetBrains AI Heading- — Central CLI, Air Alpha, and the Agentic Development Stack
x5gtrn
PRO
0
150
OpenTelemetryのメトリクスをCloudWatchに送ってPromQLで見てみた
ota1022
0
120
AIオーケストレーションを活用した 開発ワークフローの設計と実践
bqnq
0
130
AI 駆動 Terraform 開発/SRE_BizReach_MIXI_2
visional_engineering_and_design
3
2k
GoにおけるFFIのこれまでとこれから
goccy
5
2.2k
全員がプロダクトへ向き合う組織を持続成長させるために——組織づくりのフライホイールと4象限 / The Flywheel Model and Four Quadrants for Organizational Design
hiro_torii
4
950
あるけみー式LTスライド作成術
alchemy1115
1
160
作品が生態系になった ─ Mini Tokyo 3D から世界へ
nagix
0
150
AI-DLCって実際どう? 〜聞きたいこと全部聞いてみる〜
news_it_enj
0
250
アリアドネの糸と、20年ごとの建て替え ── 長尾真『電子図書館』を、伊勢で読み直す / Rereading Makoto Nagao’s "Electronic Library" in Ise
ykiyota
0
150
AIネイティブプロダクトで顧客価値を最大化するプロダクトエンジニアとFDEの協働
righttouch
PRO
0
220
Featured
See All Featured
Chrome DevTools: State of the Union 2024 - Debugging React & Beyond
addyosmani
10
1.3k
What does AI have to do with Human Rights?
axbom
PRO
1
2.4k
Visual Storytelling: How to be a Superhuman Communicator
reverentgeek
2
660
Evolution of real-time – Irina Nazarova, EuRuKo, 2024
irinanazarova
9
1.5k
Bridging the Design Gap: How Collaborative Modelling removes blockers to flow between stakeholders and teams @FastFlow conf
baasie
0
690
Designing Experiences People Love
moore
143
24k
Rails Girls Zürich Keynote
gr2m
96
14k
Fireside Chat
paigeccino
43
4k
The Myth of the Modular Monolith - Day 2 Keynote - Rails World 2024
eileencodes
28
3.6k
How to optimise 3,500 product descriptions for ecommerce in one day using ChatGPT
katarinadahlin
PRO
2
3.8k
The Organizational Zoo: Understanding Human Behavior Agility Through Metaphoric Constructive Conversations (based on the works of Arthur Shelley, Ph.D)
kimpetersen
PRO
0
440
The B2B funnel & how to create a winning content strategy
katarinadahlin
PRO
1
510
Transcript
レスポンシブから逆戻り!?WEBサービス のマルチデバイス対応方法 DAY #2 (2017/11/26) 小田島 太郎 / @shimataro 東京NODE学園祭2017
自己紹介 / / / ウェブリオ株式会社所属(京都) サーバサイドエンジニア 趣味は手品 小田島 太郎 shimataro@GitHub
odashima.taro@Facebook shimataro999@Twitter
この発表について 対象: マルチデバイス対応に苦労している人 技術レベル: 初〜中級 実戦向けの話です ↓スライドはこちら↓ https://speakerdeck.com/shimataro https://shimataro.github.io/slides/
それでは始めます
マルチデバイス対応してま すか?
3つの選択肢 1. 対応しない 2. デバイスごとに出力を変える 3. 1つの出力ですべて対応 歴史とともに説明します。
1. 対応しない デバイスを決め打ち かつてはPC向けサイトしかなかった This page is written in Japanese
only. 踏み逃げ禁止!キリ番ゲッターは要報告! 今でもやりようによっては使える
2. デバイスごとに出力を変える UAからデバイスを判別して、異なるHTMLを出力 判別方法は割愛 ガラケーの普及に伴い主流に
3. 1つの出力ですべて対応 レスポンシブウェブデザイン Googleが推奨 スマホの普及によって注目 表示はクライアント側で調整
そして今… まだレスポンシブデザインで大丈夫?
レスポンシブデザインの問 題 ガラケーに対応できない 出力内容は最大公約数的なものになる 本格的にやろうとするとメンテナンスは意外と面倒 Google AMP
GOOGLE AMPについて Accelerated Mobile Pages HTML/CSS/JSの仕様を制限 一瞬で表示! AMP専用のHTMLが必要
お分かり頂けただろうか レスポンシブデザインは万能ではない モバイル端末こそ別の出力が必要なときもある 回帰現象が起きているとでもいうのだろうか
ようやく本題 同じURLでもリクエストごとにHTMLを変えたい Node(Express)ではどうやる?
EXPRESSでのUA別出力方法 標準では用意されていない ビューを res.render() 時に切り替えるのが一般的? ページ数×デバイス数のビューが並ぶ views ├index.pug ├index-smartphone.pug └index-tablet.pug
やりたいこと デバイスごとに階層化 ソースコードの変更は最小限で! views ├default │└index.pug <- ビューはデバイスディレクトリ内に配置 ├smartphone │└index.pug
└tablet <- ビューがないデバイスでは規定のビューを表示
ミドルウェア作りました https://github.com/shimataro/express-view-switcher npm install -S express-view-switcher
使い方1: マルチデバイス対応 import viewSwitcher from "express-view-switcher"; const app = express();
app.use(viewSwitcher((req) => { // "User-Agent" ヘッダを解析して検索したいディレクトリを列挙 // ※実際の判別ロジックはREADME参照 // https://www.npmjs.com/package/express-view-switcher // 最初に見つかったビューを表示 // 1. views/smartphone // 2. views/default return [["smartphone", "default"]]; })); // あとは普通に res.render() をコール
使い方2: 多言語対応 app.use(viewSwitcher((req) => { // "Accept-Language" ヘッダやクエリストリングなどを解析 // ※実際の判別ロジックは(ry
// 1. views/en-us // 2. views/en // 3. views/ja return [["en-us", "en", "ja"]]; }));
使い方3: 多言語+マルチデバイス app.use(viewSwitcher((req) => { // 組み合わせてもOK // ※実際の(ry //
1. views/en-us/smartphone // 2. views/en-us/default // 3. views/en/smartphone // 4. views/en/default // 5. views/ja/smartphone // 6. views/ja/default return [ ["en-us", "en", "ja"], ["smartphone", "default"], ]; }));
導入してみた Weblio英会話 Perl→Node.jsに書き換え ※完了したとは言ってない ※全ページマルチデバイス対応とは言ってない https://eikaiwa.weblio.jp/
まとめ デバイスごとに出力を変えなきゃいけない状況はまだま だあるよ ミドルウェア作ったよ 多言語対応もできるよ 手品に興味があったら声をかけてね!
ご清聴ありがとうございました
おまけ ここまで見てくれてありがとう( *´艸`)
Q&A
Q: 対応バージョンは? A: Node.js 4以上 Express 4以上 動作中のNodeバージョンに合わせて最適化する素敵 仕様!
Q: REQUIRE できないよ! A: // NG: これだと使えない const viewSwitcher =
require("express-view-switcher"); // OK: 時代はES6!babelで変換しよう import viewSwitcher from "express-view-switcher"; // OK: 宗教上の理由でrequireしか使えない方はこちら const viewSwitcher = require("express-view-switcher").default;
Q: ベースディレクトリを指定したい! A: // 第二引数を指定すると、実際に使われたディレクトリが // res.locals オブジェクトのkey/valueとして追加される。 // includeやextendのベースディレクトリを指定する際に使える。
// 例: res.locals.basedir = "views/smartphone" app.use(viewSwitcher((req) => { // ※(ry return [["smartphone", "default"]]; }, "basedir")); // ただし、 "view engine" が "pug" の場合は // 自動的に "basedir" が設定されるので指定不要
Q. VARY ヘッダを指定したい! A: ごめんなさい。まだできてません。
None