简体   繁体   English

cordova / phonegap应用程序-从服务器加载js css和html

[英]cordova/phonegap app - load js css and html from server

I'm developing an cordova app for Android which has a lot of logic (js) and design (html/css) same as my web application. 我正在为Android开发Cordova应用,该应用具有与我的Web应用相同的逻辑(js)和设计(html / css)。 I want to share these assets among web app and android app. 我想在网络应用程序和Android应用程序之间共享这些资产。 Now I had compiled all these js and css in apk, but when some code is changed, I have to prepare an update and put in the play store. 现在,我已经在apk中编译了所有这些js和css,但是当某些代码更改时,我必须准备一个更新并将其放入Play商店。 If it would be possible to load code and css from server after app started, it would reduce need for upgrading. 如果有可能在应用启动后从服务器加载代码和CSS,则将减少升级需求。 Is there any way? 有什么办法吗?

I'm considering loading shared resources via ajax and dynamically creating stylesheets and scripts in DOM, but maybe there is better approach, isn't it? 我正在考虑通过ajax加载共享资源并在DOM中动态创建样式表和脚本,但是也许有更好的方法,不是吗?

You could download the files from server every time, but i think that is not what you want because it would not be availibe offline at all and if the app it big and the connection bad it will take much time to download. 您可以每次从服务器下载文件,但是我认为这不是您想要的,因为它根本无法脱机使用,如果应用程序很大且连接不良,则将花费大量时间来下载。

a better way is to download the files if they change. 更好的方法是在文件更改时下载文件。 you can do that with FileTransfer .download() yourself or use a ready solution like the cordova-standalone-hydration 您可以自己使用FileTransfer .download()进行操作,也可以使用像cordova-standalone-hydration这样的现成解决方案

BUT your app will not be accepted by for example Apple because they deny an app with code they can not check 但是您的应用程序将不会被例如Apple接受,因为它们会拒绝带有无法检查代码的应用程序

I found a plugin where you can update all your files in the WWW folder on startup or later. 我找到了一个插件,您可以在启动时或以后在WWW文件夹中更新所有文件。

Link: https://www.npmjs.com/package/cordova-plugin-dynamic-update 链接: https//www.npmjs.com/package/cordova-plugin-dynamic-update

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在Windows Store JS / HTML / CSS应用程序中使用Phonegap / Cordova插件? - Use Phonegap/Cordova plugin in Windows Store JS/HTML/CSS app? 如何将服务器端生成的新页面加载到PhoneGap或Cordova应用程序中? - How to load new pages generated server-side into a PhoneGap or Cordova app? 使用jQuery从PhoneGap应用向Node JS服务器发出AJAX请求 - Making an AJAX request with jQuery from PhoneGap app to Node JS server 在Phonegap / Cordova应用程序中使用Backbone加载HTML本地模板文件 - Load HTML local template files with Backbone in a Phonegap/Cordova application PhoneGap / Cordova编译的android应用不会加载外部URI - PhoneGap/Cordova compiled android app doesn't load external URIs 从 HTML/CSS/JS 应用程序发送电子邮件 - send an email from a HTML/CSS/JS app Angular JS App ng-href兼容Web和Phonegap / Cordova - Angular JS App ng-href compatible for Web and Phonegap / Cordova Cordova项目中使用Java而不是html,css和js - java instead of html,css and js in cordova projects 使用PhoneGap / Cordova时应用与服务器之间通信的最佳实践 - Best practice for communication between app and server when using PhoneGap/Cordova 是否可以在不重新部署的情况下更新PhoneGap应用程序中的HTML / CSS / JS文件? - Is it possible to update HTML/CSS/JS files in a PhoneGap app with out re-deploying?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM