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
Sponsored
·
SiteGround - Reliable hosting with speed, security, and support you can count on.
→
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
890
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
1k
Other Decks in Technology
See All in Technology
AIエージェントの自己改善をどう設計するか / How to Design Self-Improvement for AI Agents
22mi
25
16k
新機種発売前に見直そう!端末移行で再ログインが要るアプリ・要らないアプリは何が違うのか 〜シームレスに再開できる設計と実装〜
zozotech
PRO
0
210
あるけみー式LTスライド作成術
alchemy1115
2
220
AI時代の「技術的負債」の変質ー概念の終焉と再解釈、エージェントと共に向かう先
nwiizo
1
2.9k
.NET WebAssemblyで実現するクライアントサイドAI推論:NuGetからViteまで、2つのエコシステムを繋ぐビルド戦略
yamachu
0
190
JSONataとAWS Step Functionsで目指すRuntimelessな世界
mu7889yoon
0
190
なぜ「決定性」が 決定的に重要なのか? Durable Execution 基盤の数理的理解 #serverlessjp / ServerlessDays Tokyo 2026
ytaka23
3
710
研究開発部の紹介 / Sansan R&D Profile
sansan33
PRO
5
25k
現場で役立つ技術負債の効果的な返済方法
masuda220
PRO
9
4.6k
SREは、MCPとAutopilotをこう使え!
kazumax55
3
900
HHKBエバンジェリストになる方法
941
0
110
アクセスキーこわい やめかたと漏らさない工夫
sassssan68
1
440
Featured
See All Featured
CSS Pre-Processors: Stylus, Less & Sass
bermonpainter
360
30k
Scaling GitHub
holman
464
140k
Producing Creativity
orderedlist
PRO
348
41k
What the history of the web can teach us about the future of AI
inesmontani
PRO
1
690
Self-Hosted WebAssembly Runtime for Runtime-Neutral Checkpoint/Restore in Edge–Cloud Continuum
chikuwait
0
810
Utilizing Notion as your number one productivity tool
mfonobong
4
590
Templates, Plugins, & Blocks: Oh My! Creating the theme that thinks of everything
marktimemedia
31
2.9k
The Art of Programming - Codeland 2020
erikaheidi
57
14k
Ten Tips & Tricks for a 🌱 transition
stuffmc
1
230
From π to Pie charts
rasagy
1
370
A better future with KSS
kneath
240
18k
Making Projects Easy
brettharned
120
6.8k
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