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
·
Ship Features Fearlessly
Turn features on and off without deploys. Used by thousands of Ruby developers.
→
shimataro
November 28, 2017
Technology
330
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
Transcript
30 slides
レスポンシブから逆戻り!?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
More Decks by shimataro
See All by shimataro
作って理解するPromise / Let's try implementing Promise
shimataro
0
75
Single Executable Applicationsについて / About Single Executable Applications
shimataro
0
2.1k
パッケージ開発者の苦悩 -JavaScriptランタイム群雄割拠- / distress of package developer
shimataro
0
940
An introduction to Node.js
shimataro
0
340
KFDのススメ / About KFD
shimataro
3
890
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
870
BigInt あれこれ / overview about BigInt
shimataro
0
1k
Other Decks in Technology
See All in Technology
現場に渡し、構造で守る AI エージェントを活用したセルフサーブのデータ基盤の運用
legalontechnologies
PRO
0
150
Zero Data Loss Autonomous Recovery Service サービス概要
oracle4engineer
PRO
5
18k
「個社」ではなく「業界」の課題を解く AI 対話開発 ー 価値を広げる設計と、価値を守るエンジニアリング ー
ivry_presentationmaterials
4
920
Well, that’s weird…
csswizardry
3
260
Claude Certified Developer – Professional 試験対策
shinoisa
0
280
Platform Engineering をベースとした Agentic Software Factory の実践
110y
3
1k
AWS Well-Arhitected Frameworkセキュリティの柱 について
miu_crescent
PRO
2
270
生成AIによる情報システムへのインパクト (2026年11月版)
taka_aki
0
130
gradle-best-practices 使ってみた
mikanichinose
0
240
一口馬主の募集馬をAIで診断してみた
yoshimura_datam
0
110
フルTypeScript × AI駆動開発で開発量が数倍に (JSConf JP 2026 スポンサーLT:NCDC株式会社)
keitaibaraki
0
590
技術同人誌を作る方法
yoshimura_datam
0
110
Featured
See All Featured
Gemini Prompt Engineering: Practical Techniques for Tangible AI Outcomes
mfonobong
2
660
4 Signs Your Business is Dying
shpigford
187
23k
SERP Conf. Vienna - Web Accessibility: Optimizing for Inclusivity and SEO
sarafernandez
2
1.7k
Amusing Abliteration
ianozsvald
1
400
VelocityConf: Rendering Performance Case Studies
addyosmani
331
25k
16th Malabo Montpellier Forum Presentation
akademiya2063
PRO
0
480
The Straight Up "How To Draw Better" Workshop
denniskardys
239
140k
Into the Great Unknown - MozCon
thekraken
41
2.8k
Public Speaking Without Barfing On Your Shoes - THAT 2023
reverentgeek
1
670
Claude Code どこまでも/ Claude Code Everywhere
nwiizo
68
61k
Impact Scores and Hybrid Strategies: The future of link building
tamaranovitovic
0
490
How GitHub (no longer) Works
holman
316
150k