2015-12-22 20:41:40 +00:00
|
|
|
|
es5-ff-spa-loader
|
2015-12-23 00:16:54 +00:00
|
|
|
|
=========
|
|
|
|
|
|
2016-01-18 00:06:42 +00:00
|
|
|
|
A javascript library providing server defined loading of assets for a single page application.
|
2015-12-23 00:16:54 +00:00
|
|
|
|
|
|
|
|
|
## Installation
|
|
|
|
|
|
2016-01-18 00:06:42 +00:00
|
|
|
|
npm --save install es5-ff-spa-loader
|
2015-12-23 00:16:54 +00:00
|
|
|
|
|
2016-01-18 01:06:24 +00:00
|
|
|
|
Then use the dist/es5-ff-spa-loader.min.js script inline in the index.
|
2015-12-23 00:16:54 +00:00
|
|
|
|
|
2016-01-18 00:06:42 +00:00
|
|
|
|
## Features
|
2015-12-23 00:16:54 +00:00
|
|
|
|
|
2016-01-18 00:06:42 +00:00
|
|
|
|
* Assets caching for offline use.
|
|
|
|
|
* Assets hashing for fast syncing.
|
2016-03-13 23:52:48 +00:00
|
|
|
|
* Assets types: js,css,dss
|
2016-01-22 12:52:28 +00:00
|
|
|
|
* Caching backends: localStorage,webSqlDB,sqllite,none
|
2016-01-18 00:06:42 +00:00
|
|
|
|
* Server url question ui.
|
|
|
|
|
* Loader error ui.
|
|
|
|
|
* Build-in Cordova booting.
|
|
|
|
|
* Build-in AngularJS booting.
|
|
|
|
|
|
|
|
|
|
## Usage
|
|
|
|
|
|
|
|
|
|
### Usage Multi Server (Minimal)
|
2016-01-14 23:59:00 +00:00
|
|
|
|
|
2016-01-16 17:24:37 +00:00
|
|
|
|
FFSpaLoader.options.server.assets = '/api/path/to/spa/client/resources';
|
|
|
|
|
FFSpaLoader.start();
|
2016-01-14 23:59:00 +00:00
|
|
|
|
|
2016-01-18 00:06:42 +00:00
|
|
|
|
### Usage Single Server
|
2016-01-14 23:59:00 +00:00
|
|
|
|
|
2016-01-18 00:06:42 +00:00
|
|
|
|
FFSpaLoader.options.server.url = 'http://myserver';
|
|
|
|
|
FFSpaLoader.options.server.assets = '/api/path/to/spa/client/resources';
|
|
|
|
|
FFSpaLoader.start();
|
|
|
|
|
|
|
|
|
|
### Usage Angular
|
2016-01-14 23:59:00 +00:00
|
|
|
|
|
2016-01-16 17:24:37 +00:00
|
|
|
|
FFSpaLoader.options.debug.enable = true;
|
|
|
|
|
FFSpaLoader.options.boot.angular.modules.push('exampleUI');
|
|
|
|
|
FFSpaLoader.options.server.url = 'http://myserver';
|
|
|
|
|
FFSpaLoader.options.server.assets = '/api/path/to/spa/client/resources';
|
2016-01-14 23:59:00 +00:00
|
|
|
|
FFSpaLoader.start(function() {
|
2016-01-16 17:24:37 +00:00
|
|
|
|
console.log('FFExample.boot done');
|
2016-01-18 00:06:42 +00:00
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
## Assets format
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
"data": {
|
|
|
|
|
"resources": [
|
|
|
|
|
{
|
2016-01-22 12:52:28 +00:00
|
|
|
|
"url": "/static/js/some-asset.js",
|
2016-01-18 00:06:42 +00:00
|
|
|
|
"type": "js",
|
|
|
|
|
"hash": -164319899
|
|
|
|
|
},
|
|
|
|
|
{
|
2016-01-22 12:52:28 +00:00
|
|
|
|
"url": "/static/css/some-asset.css",
|
2016-01-18 00:06:42 +00:00
|
|
|
|
"type": "css",
|
|
|
|
|
"hash": 1391550981
|
|
|
|
|
},
|
|
|
|
|
{
|
2016-01-22 12:52:28 +00:00
|
|
|
|
"url": "/static/css/more-asset-data.css",
|
2016-03-13 23:52:48 +00:00
|
|
|
|
"type": "dss",
|
2016-01-18 00:06:42 +00:00
|
|
|
|
"hash": 1371811412
|
|
|
|
|
},
|
|
|
|
|
]
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
The hash key is required as only on hash change the resource will be downloaded again, so multiple small files makes updates faster.
|
2016-01-14 23:59:00 +00:00
|
|
|
|
|
2015-12-23 00:16:54 +00:00
|
|
|
|
|
|
|
|
|
## Options
|
|
|
|
|
|
2016-01-20 19:35:43 +00:00
|
|
|
|
The available FFSpaLoader.options.* values;
|
|
|
|
|
|
2016-01-18 00:06:42 +00:00
|
|
|
|
* debug.enable = Enable debug output. (default: false)
|
|
|
|
|
* debug.handler = Prints/log debug message. (default: console.log)
|
|
|
|
|
* debug.prefix = Debug message prefix. (default: 'FFSpaLoader.')
|
|
|
|
|
* error.handler = The error handler. (default: internal error handler ui)
|
2016-01-20 20:57:05 +00:00
|
|
|
|
* error.title = The error title. (default: 'Loader ');
|
2016-01-18 00:06:42 +00:00
|
|
|
|
* boot.cordova.enable = Use deviceready event to boot when cordova is detected. (default: true)
|
2016-01-20 19:35:43 +00:00
|
|
|
|
* boot.cordova.timeout = Boot after (if<0=no-)timeout when deviceready event is not received. (default: -1)
|
2016-01-18 00:06:42 +00:00
|
|
|
|
* boot.cordova.flag = The window flag which is set when cordova is booted. (default: 'FFCordovaDevice')
|
|
|
|
|
* boot.angular.enable = Auto bootstrap angular modules. (default: true)
|
|
|
|
|
* boot.angular.modules = The angular modules to boot. (default: empty)
|
2016-03-16 20:58:27 +00:00
|
|
|
|
* boot.cleanup.enable = Auto cleanup the loader html tags. (default: true)
|
|
|
|
|
* boot.cleanup.timeout = Cleanup after timeout(in ms) so css effects are done. (default: 1000)
|
|
|
|
|
* boot.cleanup.tags = The array of tag ids to remove. (default: empty)
|
2016-01-18 00:06:42 +00:00
|
|
|
|
* server.url = The server url like 'https://myhost', when null the user will get promted to input it. (default: null)
|
2016-04-20 16:15:23 +00:00
|
|
|
|
* server.depath = Strip this path from the server.url needed when the ui has prefix from application root.
|
2016-01-18 00:06:42 +00:00
|
|
|
|
* server.assets = The server path to the assets resources definition file, is required (default: null)
|
2016-01-18 21:41:52 +00:00
|
|
|
|
* server.timeout = The timeout to download the server resources. (default: 4096)
|
2016-01-18 00:06:42 +00:00
|
|
|
|
* server.flag = The window flag which is set when the server.url is know. (default: 'FFServerUrl')
|
2016-01-21 21:41:56 +00:00
|
|
|
|
* server.header.request = An key value object with the request headers. (default: {'X-FFSpaLoader': 'sync'})
|
2016-02-26 23:24:43 +00:00
|
|
|
|
* server.header.response = An key value object with the required response headers. (default: {})
|
2016-01-21 19:42:18 +00:00
|
|
|
|
* question.transport = The transport to prefix the server.url with. (default: 'http://')
|
|
|
|
|
* question.title = The question ui title. (default: 'Server')
|
2016-01-21 23:02:39 +00:00
|
|
|
|
* question.submit = The start button text. (default: 'Start')
|
2016-01-21 19:42:18 +00:00
|
|
|
|
* question.text = The question ui text. (default: 'Please provide the server name;')
|
2016-01-24 17:58:52 +00:00
|
|
|
|
* question.size = The question ui input size. (default: 32)
|
2016-01-21 21:17:22 +00:00
|
|
|
|
* question.validate.min.value = The minimal hostname length, false is disabled (default: 3)
|
|
|
|
|
* question.validate.min.message = The error message (default: 'Server name is to short.')
|
|
|
|
|
* question.validate.max.value = The maximal hostname length, false is disabled (default: 255)
|
|
|
|
|
* question.validate.max.message =The error message (default: 'Server name is to long.')
|
|
|
|
|
* question.validate.regex.value = The regex to validate the hostname, false is disabled. (default: '^([a-zA-Z0-9\.\:])*$')
|
|
|
|
|
* question.validate.regex.message = The error message (default: 'Server name is invalid.')
|
2016-02-26 22:40:29 +00:00
|
|
|
|
* loader.title = The loader title (default: 'Loading Application')
|
|
|
|
|
* loader.footer = The loader footer (default: '© FFSpaLoader')
|
|
|
|
|
* loader.await = The timeout in ms before the loader displays. (default: 250)
|
|
|
|
|
* loader.progres.items.enable = Enables the per item progres. (default: true)
|
|
|
|
|
* loader.progres.items.size = Shorten longer urls to this size. (default: 50)
|
|
|
|
|
* loader.progres.bar.enable = Enables the progres bar. (default: true)
|
|
|
|
|
* loader.progres.bar.percentage = Print percentage's in bar. (default: true)
|
2016-01-21 21:17:22 +00:00
|
|
|
|
* cache.meta = The cache backend for the meta information(server.url+content), null is auto select,false is disable. (default: null)
|
|
|
|
|
* cache.js = The cache backend for for js, null is auto select,false is disable. (default: null)
|
|
|
|
|
* cache.css = The cache backend for for css, null is auto select,false is disable. (default: null)
|
2016-03-13 23:52:48 +00:00
|
|
|
|
* cache.dss = The cache backend for for dss, null is auto select,false is disable. (default: null)
|
2016-01-18 00:06:42 +00:00
|
|
|
|
|
2016-01-24 18:44:00 +00:00
|
|
|
|
## Functions
|
|
|
|
|
|
|
|
|
|
The functions iin FFSpaLoader.*;
|
|
|
|
|
|
|
|
|
|
* clearServerUrl(cb) = Clears the cached server url so after reload user get promted again.
|
|
|
|
|
* clearCache(cb) = Clears the cached values so after reload all assets get refetched.
|
2016-01-20 19:35:43 +00:00
|
|
|
|
|
|
|
|
|
## Factory
|
|
|
|
|
|
|
|
|
|
The available FFSpaLoader.factory.* functions;
|
|
|
|
|
|
|
|
|
|
* detect.localStorage() = Checks is localStorage is working.
|
|
|
|
|
* detect.openDatabase() = Checks if openDatabase is defined.
|
|
|
|
|
* detect.sqlitePlugin() = Checks if sqlitePlugin is defined.
|
|
|
|
|
* detect.cordova() = Checks if cordova is defined.
|
2016-01-22 14:44:43 +00:00
|
|
|
|
* detect.cordovaDevice() = Checks if the options.boot.cordova.flag is defined in the window.(NOTE: is always false before calling start();)
|
2016-01-20 19:35:43 +00:00
|
|
|
|
* cache.localStorage() = Creates an localStorage service.
|
|
|
|
|
* cache.websql(opt) = Creates an websql service.
|
|
|
|
|
|
2016-01-22 14:44:43 +00:00
|
|
|
|
## Cache Types
|
|
|
|
|
|
|
|
|
|
The cache types in FFSpaLoader.options.cache.* store different types data;
|
|
|
|
|
|
2016-01-24 21:03:24 +00:00
|
|
|
|
* meta = Stores the server url and server assets.
|
2016-01-22 14:44:43 +00:00
|
|
|
|
* js = Store application javascript data.
|
|
|
|
|
* css = Stores application css data.
|
2016-03-13 23:52:48 +00:00
|
|
|
|
* dss = Stores application css large data like base64 fonts/svg/etc.
|
2016-01-22 14:44:43 +00:00
|
|
|
|
|
2016-01-18 00:06:42 +00:00
|
|
|
|
## Cache Config
|
|
|
|
|
|
2016-01-22 14:44:43 +00:00
|
|
|
|
Per default all cache types are auto selected in the following order;
|
2016-01-18 00:06:42 +00:00
|
|
|
|
|
2016-01-22 14:44:43 +00:00
|
|
|
|
* detect.sqlitePlugin() and detect.cordovaDevice()
|
|
|
|
|
* detect.openDatabase()
|
|
|
|
|
* detect.localStorage()
|
2016-01-18 00:06:42 +00:00
|
|
|
|
* none
|
|
|
|
|
|
2016-01-18 01:06:24 +00:00
|
|
|
|
More custom schemas are possible like; (todo: needs testing)
|
2016-01-18 00:06:42 +00:00
|
|
|
|
|
2016-01-21 00:40:15 +00:00
|
|
|
|
FFSpaLoader.options.cache.meta = false;
|
2016-01-18 00:06:42 +00:00
|
|
|
|
FFSpaLoader.options.cache.js = false;
|
|
|
|
|
FFSpaLoader.options.cache.css = false;
|
2016-03-13 23:52:48 +00:00
|
|
|
|
FFSpaLoader.options.cache.dss = false;
|
2016-01-18 00:06:42 +00:00
|
|
|
|
|
|
|
|
|
if (FFSpaLoader.factory.detect.localStorage()) {
|
2016-01-21 21:48:45 +00:00
|
|
|
|
FFSpaLoader.options.cache.css = FFSpaLoader.factory.cache.localStorage();
|
2016-03-13 23:52:48 +00:00
|
|
|
|
FFSpaLoader.options.cache.dss = FFSpaLoader.factory.cache.localStorage();
|
2016-01-22 14:44:43 +00:00
|
|
|
|
}
|
|
|
|
|
FFSpaLoader.options.server.url = 'http://myserver';
|
2016-01-18 00:06:42 +00:00
|
|
|
|
FFSpaLoader.options.server.assets = '/api/path/to/spa/client/resources';
|
|
|
|
|
FFSpaLoader.start();
|
|
|
|
|
|
2015-12-23 00:16:54 +00:00
|
|
|
|
|
|
|
|
|
## Example Application
|
|
|
|
|
|
2016-01-24 21:03:24 +00:00
|
|
|
|
There is a nodejs example application in the example folder;
|
2015-12-23 00:16:54 +00:00
|
|
|
|
|
2016-01-24 21:03:24 +00:00
|
|
|
|
* git clone https://bitbucket.org/im_ik/es5-ff-spa-loader.git
|
2016-01-24 20:38:21 +00:00
|
|
|
|
* cd es5-ff-spa-loader
|
|
|
|
|
* cd example
|
|
|
|
|
* npm install
|
|
|
|
|
* npm start
|
|
|
|
|
|
|
|
|
|
For the mobile example install+build steps are;
|
|
|
|
|
|
|
|
|
|
* export ANDROID_HOME=/my/android-sdk/path
|
|
|
|
|
* npm install cordova -g
|
|
|
|
|
* cd es5-ff-spa-loader
|
|
|
|
|
* cd example
|
|
|
|
|
* cd app_mobile
|
|
|
|
|
* cordova platform add android
|
|
|
|
|
* cordova build
|
|
|
|
|
|
2016-01-16 17:24:37 +00:00
|
|
|
|
## Tested Browsers
|
|
|
|
|
|
|
|
|
|
* Chromium 46
|
|
|
|
|
* Iceweasel 43
|
2016-01-24 21:03:24 +00:00
|
|
|
|
* Firefox Aurora 45
|
2016-01-16 17:24:37 +00:00
|
|
|
|
* Opera 12 Presto
|
2016-01-20 20:57:05 +00:00
|
|
|
|
* IE 11 Edge
|
2016-01-23 18:25:20 +00:00
|
|
|
|
* Android 5.1.1 in Cordova + Site
|
2016-01-24 17:58:52 +00:00
|
|
|
|
* Android 4.4.4 in Cordova + Site
|
2016-01-23 18:25:20 +00:00
|
|
|
|
* Android 4.2.2 in Cordova + Site
|
2016-01-17 20:57:59 +00:00
|
|
|
|
|
|
|
|
|
## Todo
|
|
|
|
|
|
|
|
|
|
* test in production
|
2016-01-24 21:03:24 +00:00
|
|
|
|
* Add instance websql options so it can also be used in application code.
|
2016-03-13 23:52:48 +00:00
|
|
|
|
* Split assets per type so do js first then boot then css + dss.
|
2016-01-17 20:57:59 +00:00
|
|
|
|
* Add more tests
|
|
|
|
|
* css: set tag.media = 'only you';
|
|
|
|
|
* css: add media in resouces
|
2016-01-24 17:58:52 +00:00
|
|
|
|
* Add in browser tests
|
2016-01-24 20:43:11 +00:00
|
|
|
|
* example: Cache angular template for offline mode.
|
2016-04-20 16:15:23 +00:00
|
|
|
|
* cache limits for soft fallback to injecting ?
|
2016-01-16 17:24:37 +00:00
|
|
|
|
|
2015-12-23 00:16:54 +00:00
|
|
|
|
## Contributing
|
|
|
|
|
|
|
|
|
|
In lieu of a formal styleguide, take care to maintain the existing coding style.
|
|
|
|
|
Add unit tests for any new or changed functionality. Lint and test your code.
|
|
|
|
|
|
|
|
|
|
## Release History
|
|
|
|
|
|
2016-04-20 16:15:23 +00:00
|
|
|
|
### 0.2.2
|
|
|
|
|
* Fixed clearServerUrl() to also clean the cached server resources json.
|
|
|
|
|
* Auto clean option.server.url from # and ? endings for: FFSpaLoader.options.server.url = window.location.href;
|
|
|
|
|
* Added server.depath option to strip the ui-prefix from the server.url.
|
|
|
|
|
* Added auto resetting server.url when is file:// for "Page save as" feature.
|
|
|
|
|
* Fixed askUrl to accept host and context path with auto clean/depathing.
|
|
|
|
|
* Fixed duplicate starts on askUrl submit multiple clicks.
|
2016-04-22 08:34:11 +00:00
|
|
|
|
* Switch to karma + jasmine unit tests.
|
|
|
|
|
* Fixed define.amd module constructor.
|
2016-04-20 16:15:23 +00:00
|
|
|
|
|
2016-03-16 20:58:27 +00:00
|
|
|
|
### 0.2.1
|
|
|
|
|
* Fixed clearCache method to added json header.
|
|
|
|
|
* Added url to non 200 http status error message.
|
|
|
|
|
* Added boot.cleanup.tags options.
|
|
|
|
|
|
2016-02-16 15:09:23 +00:00
|
|
|
|
### 0.2.0
|
2016-02-26 23:24:43 +00:00
|
|
|
|
* Moved error.style and question.style to css file.
|
2016-03-13 23:26:00 +00:00
|
|
|
|
* Changed dist with extra css/js folder.
|
2016-02-26 22:40:29 +00:00
|
|
|
|
* Added loader progress bar.
|
|
|
|
|
* refined css so question/loader/error are equal.
|
2016-02-26 23:24:43 +00:00
|
|
|
|
* Added response header check support.
|
2016-03-13 23:26:00 +00:00
|
|
|
|
* Added json accept header on assets resources list.
|
2016-03-13 23:42:10 +00:00
|
|
|
|
* Added cb errors on assets resources json parse + result obj.
|
2016-03-13 23:52:48 +00:00
|
|
|
|
* Renamed cssData type to dss for enum easiness.
|
2016-03-14 00:50:47 +00:00
|
|
|
|
* Added unknown resource type error.
|
2016-02-16 15:09:23 +00:00
|
|
|
|
|
2016-01-22 14:44:43 +00:00
|
|
|
|
### 0.1.1
|
|
|
|
|
* Moved websql delete timeout to cleanServerlUrl for faster boot.
|
2016-01-23 18:25:20 +00:00
|
|
|
|
* Fixed websql db-size and db-name for older androids.
|
2016-01-24 17:58:52 +00:00
|
|
|
|
* Added more jsdoc.
|
|
|
|
|
* Added question.size option.
|
|
|
|
|
* Changed websql option openDatabase to returning open function.
|
2016-01-24 21:03:24 +00:00
|
|
|
|
* Fixed sqlitePlugin open function was 2x typo on openDatabase.
|
2016-01-24 17:58:52 +00:00
|
|
|
|
* Added websql table option. (defaults to 'cache_store')
|
2016-01-24 18:44:00 +00:00
|
|
|
|
* Added clearCache function.
|
2016-01-24 20:38:21 +00:00
|
|
|
|
* Fixed removed question div on loader error.
|
|
|
|
|
* Updated example and removed it from npm.
|
2016-01-24 20:43:11 +00:00
|
|
|
|
* Added cordova app with example.
|
2016-01-24 20:38:21 +00:00
|
|
|
|
|
2016-01-21 19:42:18 +00:00
|
|
|
|
### 0.1.0
|
2016-01-24 17:58:52 +00:00
|
|
|
|
* Moved options.server.question to options.question.
|
2016-01-21 21:17:22 +00:00
|
|
|
|
* Added question.validate.[min|max|regex].value|message options.
|
|
|
|
|
* Strip question value to hostname+port before use and validating.
|
|
|
|
|
* Allow user upgrade to https in question input from default of transport option.
|
2016-01-21 23:02:39 +00:00
|
|
|
|
* Added server request headers option.
|
|
|
|
|
* Updated css of question and error ui.
|
2016-01-22 12:52:28 +00:00
|
|
|
|
* Fixed cordova booting.
|
2016-01-21 19:42:18 +00:00
|
|
|
|
|
2016-01-20 19:35:43 +00:00
|
|
|
|
### 0.0.4
|
2016-01-24 17:58:52 +00:00
|
|
|
|
* Added auto cache clean code.
|
2016-01-20 19:35:43 +00:00
|
|
|
|
* Disable cordova timeout per default.
|
|
|
|
|
* Remove unused mobileAgent detect.
|
2016-01-21 00:40:15 +00:00
|
|
|
|
* Fixed cached resources injection order.
|
2016-01-20 19:35:43 +00:00
|
|
|
|
|
2016-01-18 01:06:24 +00:00
|
|
|
|
### 0.0.3
|
2016-01-20 19:35:43 +00:00
|
|
|
|
* Fixed example script path.
|
|
|
|
|
* Fixed example size.
|
|
|
|
|
* Initial release.
|