Angular-Cli force component to reload image cache

前端 未结 1 718
滥情空心
滥情空心 2021-01-16 16:27

I have a project in Angular CLI, it has the lft menu (where I store some navigation and user informations include user image. On the right side there is oth

相关标签:
1条回答
  • 2021-01-16 16:55

    If I understand, the browser doesn't do request to image, because it's cached. It's because image path is the same.

    So you can put timestamp to image path at the end:

     //   <img [src] = '/path/to/image?timeStamp=123123' />
    
    
        class SomeComponent{
        imageSrc: string = '/path/to/image';
    //    getTimeStamp(): number{
    //     return Date.now();
    //    }
    
        // or call this when you need update image
    
        updateImageSrc(): string{
           this.imageSrc= `/path/to/image?timeStamp=${Date.now()}`
    
        }
    
        }
    

    Update:

     <img [src] = "imageSrc" />
    

    Code example. Look at network tab

    0 讨论(0)
提交回复
热议问题