Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(livereload): Images not loading #161

Merged
merged 7 commits into from
Jun 29, 2018
9 changes: 7 additions & 2 deletions src/providers/image-loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -414,12 +414,19 @@ export class ImageLoader {
* @returns {Promise<string>} Returns a promise that resolves with the local path if exists, or rejects if doesn't exist
*/
private getCachedImagePath(url: string): Promise<string> {
// Check if we're running with livereload
let _isDev: boolean = (window['IonicDevServer'] != undefined);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. If the IonicDevServer variable is defined before the app loads, it makes more sense to make this a global variable (either a variable outside the class, or a private property of the class). This way we don't have to evaluate the expression every time getCachedImagePath is called.

return new Promise<string>((resolve, reject) => {

// make sure cache is ready
if (!this.isCacheReady) {
return reject();
}

// if we're running with livereload, ignore cache and call the resource from it's URL
if(!!_isDev){
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

!! is not required.. since window['IonicDevServer'] != undefined or typeof window['IonicDevServer'] !== 'undefined' will always return a boolean

return reject();
}

// get file name
const fileName = this.createFileName(url);
Expand Down Expand Up @@ -452,10 +459,8 @@ export class ImageLoader {
// in this case only the tempDirectory is accessible,
// therefore the file needs to be copied into that directory first!
if (this.isIonicWKWebView) {

// Use Ionic normalizeUrl to generate the right URL for Ionic WKWebView
resolve(normalizeURL(fileEntry.nativeURL));

} else if (this.isWKWebView) {

// check if file already exists in temp directory
Expand Down