首页 > jsp图片缓存怎么做?

jsp图片缓存怎么做?

我有一个网站,首页有几张轮播的大图,是使用background来指定滚动图片的,由于图片很大,导致加载超级慢,而且不知道怎么回事,每次刷新都会重新请求,也就是200 OK,而不是304 Not Modified。请问我要怎么优化,缓存这些background图片。 我用的是jsp技术。 有此类方案的希望提点下,谢谢。


你可以在服务器设置静态文件缓存时间或者response.setHeader设置header头告诉浏览器缓存

Apache:

# enable the directives - assuming they're not enabled globally
ExpiresActive on

# send an Expires: header for each of these mimetypes (as defined by server)
ExpiresByType image/png "access plus 1 month"
ExpiresByType image/gif "access plus 1 month"
ExpiresByType image/jpeg "access plus 1 month"

Nginx:

location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
        {
            expires      30d;
        }

        location ~ .*\.(js|css)?$
        {
            expires      12h;
        }
【热门文章】
【热门文章】