How to make github-hosted interactive demo app in HTML5+Javascript that works both online and offline

95 views Asked by At

I'm trying to make small interactive physics demos and mini-games which should work

  1. offline - by simply opening the .html file in browser (preferably without any localhost web server)
  2. online - hosted on github and using http://rawgit.com/

But I met several problems:

  1. Online I have to load *.js libraries from cdnjs while offline I have to load them from some local file. How to make .html that will automatically load dependencies from proper source?
  2. Composing the web page from several independent files also works differently online and offline
  3. Loading resources (shaders, 3D geometry objects) from external files - the same story.
    • For example, how can I let user to choose (e.g. depending on some <select> widget) which shader or 3D model to load from files hosted on gihub server ?
  4. The most painful is file I/O to user hard-drive (i.e. to save and load data which user created). For some security reasons file browsers does not support it, and solutions which I found are either a) not working or b) terribly complicated workaround or c) having many dependencies (jQuery). Best what I found is this save and load.

These problems gets better if I run some localhost server (simplest is to use python). But this makes it inconvenient for the end user. I would like a .html file which the end-user can simply open offline in his web browser and it would work without any server.

Is node.js environment somehow relevant / useful for this purpose?

Examples:

There is some example of what I'm doing: https://rawgit.com/ProkopHapala/SimpleSimulationEngine/master/projects/SpaceCombat/HTML/StickSpaceCraft.html

There is example which works well offline but not online: https://github.com/ProkopHapala/SimpleSimulationEngine/blob/master/js/PlanetDesigner/PlanetDesigner.html

background: I was never interested in web technologies. But recently I found that javascript with WebGL and other HTML5 stuff can be greatly useful in areas which interests me (numerical math, physics, 3D graphics, games). Inspired by examples 1, 2, 3, 4, I started to learn javascript and HTML with goal to make simple demo which interactively illustrates some problem from my domain of interest.

1

There are 1 answers

0
Ashkan On

As I know you can only use frontend technologies in github, so you must leave the node.

But for making your app work both offline and online, You might be able to build a CACHE MANIFEST file (for example offline.manifest) and write the files you want to be cached in them. for example:

CACHE MANIFEST
mystyles.css
image/mypic.jpg
jquery-1.4.min.js
script.js
index.html 

and load it with manifest attribute in your html:

<html manifest="offline.manifest">

There is a technology by the named of indexedDB, Which you can use it as a front-end Database. You can use this too.