首页
Wiki
Reviews
Business
Dewshelf
Plaza
Language Sites
what todayorigin
origin
Login
Register
☰
OPPO 快游戏在浏览器复现运行(七)之远程资源离线化
News and information
2026-08-09
deps
err
bundle
names
name
function
const
return
2°
**完全的离线化仅适用于走快游戏 API 的资源,部分资源是直接通过 `img` 标签或者其他方式加载的(最终会 fallback 到 XHR)还是会到本地服务器发起请求。`web.sdk.js` 不对此类资源做特殊拦截处理,做离线化的本意是解决版本更新后在线资源的失效问题,对快游戏做 web 移植本身就需要一个静态服务器托管,所以这个并不算大问题。如果需要完完全全的离线化,可自行对游戏逻辑做魔改拦截。** 针对使用 Cocos Creator 框架制作的游戏,在 `_CCSettings` 中一般能看到以下字段:`remoteBundles`、`bundleVers`,`remoteBundles`是远程 Bundle 列表,`bundleVers`是所有 Bundle 列表,比如: ```js window._CCSettings = { remoteBundles: ["resources"], bundleVers: { internal:"b3cad", b0:"10607", b1:"f37a4", data:"5bf88", resources:"011ae", main:"c0c83" } }; ``` 远程 Bundle 可能会依赖其他 Bundle,为了远程 Bundle 能顺利的加载,需要先通过 `loadBundle` 拿到 Bundle 配置中的 `deps`,统计完整依赖链,再按依赖顺序逐个加载。 ```js async function loadCCBundle(names, unload = false) { names = Array.isArray(names) ? names : [names]; const bundles = Object.create(null); const visited = Object.create(null); const visiting = Object.create(null); const order = []; function unloadBundle(name) { const bundle = cc.assetManager.getBundle(name); if (bundle) { bundle.releaseAll(); cc.assetManager.removeBundle(bundle); } } function loadBundle(name) { return new Promise(function (resolve, reject) { if (unload) { unloadBundle(name); } const exists = cc.assetManager.getBundle(name); if (exists) { resolve(exists); return; } cc.assetManager.loadBundle(name, function (err, bundle) { if (err) { reject(err); return; } resolve(bundle); }); }); } function loadDir(bundle) { return new Promise(function (resolve, reject) { window.qg.consolelog('loadDir start: ' + bundle.name); bundle.loadDir('', function (err) { if (err) { reject(err); return; } window.qg.consolelog(bundle.name + ' resources loaded'); resolve(bundle); }); }); } async function visit(name, stack) { if (visited[name]) { return; } if (visiting[name]) { throw new Error('Circular bundle deps: ' + stack['concat'](name).join(' -> ')); } visiting[name] = true; const bundle = await loadBundle(name); const deps = bundle.deps || []; bundles[name] = bundle; window.qg.consolelog('bundle deps: ' + name + ' -> ' + JSON.stringify(deps)); for (let i = 0; i < deps.length; i++) { await visit(deps[i], stack['concat'](name)); } visiting[name] = false; visited[name] = true; order.push(name); } try { for (let i = 0; i < names.length; i++) { await visit(names[i], []); } window.qg.consolelog('bundle load order: ' + order.join(' -> ')); for (let i = 0; i < order.length; i++) { const name = order[i]; const bundle = bundles[name] || await loadBundle(name); await loadDir(bundle); } window.qg.consolelog('all bundle resources loaded'); } catch (err) { window.qg.consoleerror(err); } } // 然后就可以正式下载远程 Bundle 了 loadCCBundle(window._CCSettings.remoteBundles); ``` 此时应该可以看到控制台已经在疯狂下载资源了,但还不够,因为我们需要将这些资源保存放到本地,以便后续离线化加载。 这时候就到了 `remote-cache` 上场了,它本质上就是一个转发保存程序,收到请求后,重定向到真正的远程资源,并将资源原样返回的同时将资源保存到本地。 修改 `_CCSettings` 中的 `server` 字段: ```js window._CCSettings = { server: `http://127.0.0.1:9999/${originServer}`, }; ``` 然后再次尝试 `loadCCBundle`,当所有远程 Bundle 都进行 `loadCCBundle`之后,就可以对 `_CCSettings` 中的 `server` 字段做一个小调整,将远程资源改成本地资源: ```js window._CCSettings = { server: `/https.xxx.com/xxxxxxxxxx`, }; ``` 此时游戏已经完成远程资源的本地化了。 某些游戏是运行时通过 JS 动态加载的,此类逻辑没法提前预加载,只能通过人工的方式去到对应的场景下触发下载,做这类逻辑的游戏一般都比较捞。
Related
认领罗曼望远镜像素点
解决 Codex 无法访问 rg.exe 的问题
分享一下近期爆火的AI人脸、姿势、服装素材库
Digital Accessibility Ethics Book Discussion Guide
The Digital Accessibility Ethics Framework Values, Actions, and Questions for Disability Inclusion in Tech
Stock Photo Sites for Inclusion
Digital Accessibility Ethics for Publishers and Librarians A Disability Inclusion in Tech Resource
Why Digital Accessibility? Because it is an Ethical Imperative Text of 15 minute talk at M-Enabling Summit 2026
$240,000.00 Jury Verdict in Blind Students’ Accessibility Lawsuit against Community College Judge's effort to throw out the verdict rejected on appeal
Why Accessibility Overlays Don’t Work: Findings from U.S. State Government Websites Guest Article by Digital Accessibility Specialists Alison Walden and Matt Vitale
Legal Update: Accessibility Overlay Edition [With 2026 Updates]
Lainey Feingold’s Law Office Turns 30
Title II Web and Mobile Technical Accessibility Standards: History + Current Status It took 14 years to get this Rule: Good thing the ADA requires access even without the new regulations
Announcing the Special Interest Group (SIG) for Ray on Accelerators
KVCache Meetup Korea 2026: Event Recap
OPPO 快游戏在浏览器复现运行(六)之触摸适配
OPPO 快游戏在浏览器复现运行(五)之竖屏适配
解决 WSL2 莫名其妙的远程桌面报错弹窗
某 Telegram AI陪聊 任意注册账号漏洞
某 Telegram AI陪聊 跨渠道登录漏洞
OPPO 快游戏在浏览器复现运行(四)之游戏入口加载
How to Get Promoted: The 6 Steps to Take Control of Your Career
The Fine Line Between Being a Great Leader and Being Annoying
12 Things I Learned in Big Tech
Stop Trying Harder. Change Your Environment Instead.
How Amazon Uses Tenets to Make Better Decisions at Every Level
4 Steps to Changing People's Perceptions
Why Great Engineering Teams Don't Need Productivity Metrics
The Ambitious Leader's Guide to Avoiding Burnout
The Secret to Sounding Like a Senior Leader? Say Less.
Find Your Interest
So Darn Good
What's left for infrastructure-as-code after AI moves in?
Secure your CODE!
Your code sucks!
100: The Return of Jon Cadieux
Just Visiting
Code Reviews
Dealing with Code breakers
Dealing with Code breakers
Code Reviews
Related Goods
双面绒大衣女百搭宽松显瘦韩版过膝中长款气质时尚毛呢遮肉显瘦
$15.57
https://en.orbuy.net
https://www.orbuy.net
chic奶fufu的毛衣女春秋复古设计感两穿纽扣针织上衣女单排扣开衫
$3.94
https://en.orbuy.net
https://www.orbuy.net
领洋气开衫上档次新款百搭针织衫纯色外搭休闲毛衣潮流打底衫女
$5.16
https://en.orbuy.net
https://www.orbuy.net
高清微單CCD數碼相機學生入門級復古旅拍vlog隨身便攜翻轉屏相機
$13.41
https://en.orbuy.net
https://www.orbuy.net
复古时尚彩扣毛衣外套女春秋新款宽松圆领休闲百搭针织开衫上衣
$6.54
https://en.orbuy.net
https://www.orbuy.net
中老年大码斤金丝绒连衣裙高贵洋气女装妈妈装秋冬中长裙女
$4.17
https://en.orbuy.net
https://www.orbuy.net
Hot Tags
新款(406)
针织衫(180)
时尚(174)
秋冬(108)
针织(106)
儿童(98)
跨境(98)
毛衣(97)
收纳盒(75)
两件套(73)
家用(73)
韩系(72)
秋季(71)
春秋(69)
复古(69)
洋气(66)
大容量(64)
蓝牙(64)
长袖(61)
开衫(57)