简体   繁体   English

Angular:在firefox中使用img ng-src时缓存图像似乎已经破了

[英]Angular: caching of images when using img ng-src in firefox seems broken

I'm working on a real-time photosharing website. 我正在开发一个实时的照片共享网站。 It allows users across the world to look at photos together and post comments on them, with a real-time view of who is looking at what. 它允许世界各地的用户一起查看照片并在其上发表评论,并实时查看谁在看什么。

I used to use jQuery DOM manipulation (insertion of <img> tags) to show different images based on what the user clicked, and recently replaced this presentation logic with an Angular controller with an ng-src directive. 我曾经使用jQuery DOM操作(插入<img>标签)来根据用户点击的内容显示不同的图像,最近用带有ng-src指令的Angular控制器替换了这个表示逻辑。

The logic works overall, but I noticed that on Firefox, Angular makes a GET request every single time I change the ng-src value, when I expect that image to be cached on the browser. 整个逻辑工作,但我注意到在Firefox上,当我希望在浏览器上缓存图像时,Angular会每次更改ng-src值时发出一个GET请求。

If you go here: http://dev14-www.photozzap.com/conference/j4bxpt3n , then open up Firebug / Net view, and switch back and forth between two photos, you will see that it makes GET requests for the image even though those images should be in the cache. 如果你去这里: http//dev14-www.photozzap.com/conference/j4bxpt3n ,然后打开Firebug / Net视图,并在两张照片之间来回切换,你会看到它对图像的GET请求甚至虽然这些图像应该在缓存中。

The impact is that the user will see some lag between the time they click on a photo and the time it actually displays. 影响是用户在点击照片的时间和实际显示的时间之间会看到一些延迟。

On Chrome, the Developer / Net view clearly shows that the image is pulled from the cache when switching back and forth between images. 在Chrome上,开发人员/网络视图清楚地显示在图像之间来回切换时从高速缓存中提取图像。

Can my code be fixed to allow images to be cached on Firefox or is there an Angular issue there ? 可以修复我的代码以允许在Firefox上缓存图像或者是否存在Angular问题? Chrome seems to be doing the right thing. Chrome似乎正在做正确的事情。

I'm on Firefox 24, and I can confirm, that requests are actually made every time I switch between photos, but... As you can see by investigating details of such request, server responds with 304 Not Modified, so image data itself isn't transfered over and over again so performance won't suffer much. 我在Firefox 24上,我可以确认,每次我在照片之间切换时都会发出请求,但是......正如您通过调查此类请求的详细信息所看到的那样,服务器响应304 Not Modified,因此图像数据本身不会一次又一次地转移,所以性能不会受到太大影响。

Even though firefox has stored image in cache, it's making a request to check if the image has been changed, upon seeing 304 response it just displays the local version of the file. 尽管firefox已将图像存储在缓存中,但它正在请求检查图像是否已更改,在看到304响应后,它只显示文件的本地版本。

This is a firebug issue. 这是一个萤火虫问题。 If you inspect your traffic with a proxy, you will see that without firebug activated, it will not request the images from the server again, so any regular user will be fine. 如果您使用代理检查流量,您将看到没有激活firebug,它将不会再次从服务器请求图像,因此任何常规用户都可以。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM