1.0.2 • Published 4 years ago
lsnj-update-check v1.0.2
LSNJ Update Check
This library was created to force, the client browser, to refresh the cache, after a new deployment.
How to use
app.module.ts
Add to your app.module.ts the service LsnjUpdateCheckService in the providers list.
import { LsnjUpdateCheckService } from 'lsnj-update-check'; @NgModule({ ... providers:[ ... LsnjUpdateCheckService, ... ], ... })
If you need to inject a service, like a DialogService, before to refresh the cache, you can inject the service in the providers list.
import { LsnjUpdateCheckService } from 'lsnj-update-check'; @NgModule({ ... providers:[ ... LsnjUpdateCheckService, { provide: 'dialogService', useClass : MatDialogService} ... ], ... })
app.component.ts
Modify your app.component.ts like the following example.
import { LsnjUpdateCheckService } from 'lsnj-update-check'; export class AppComponent implements OnInit { constructor(private _versionCheckService : LsnjUpdateCheckService) {} ... ngOnInit(): void { this._versionCheckService.initVersionCheck( 'http://www.example.com/version.js', //Url to the file version.json this.versionCheckerCallBack, // Callback method verCheckerEnv.checkVersionEvery // Interval in minute to Check new version); } private versionCheckerCallBack(response: any) { window.location.reload(); //reload page on new version released } ... }
How to build
package.json
Included in this package, you have a script to automatically modify the hash value, generated by the build process, inside the main.js file. Add these commands to automatically run the JS script build-post.js, after the transpile process.
"scripts": { ... "build:prod": "ng build --prod --output-hashing=all && npm run post-build", "post-build": "node ./node_modules/lsnj-update-check/build/post-build.js", ... }
Build command
Build your project with this command.
npm run build:prod
Check the browser console
Console messages
CHECK VERSION Current Version: Ver. 1.0.0 Hash: 78813ecc046b7379f4f1 Nothing to do...