在我的春节,启动/应用程序做出反应,我想缓存bundle.js(1.2MB)。如果我使用http://(test-envionment-server-url)/myapp运行应用程序,则每次刷新页面时,我的bundle.js都会从状态304的缓存(208 B)中调用。到现在为止一切都很好。 但是当我使用https://(test-envionment-server-url)/myapp bundle.js不被缓存,每次我刷新它得到所有1.2MB,但所有其他图像和字体得到缓存。的WebPack /反应,和/春启动:缓存bundle.js以https
我在本地使用Tomcat和JBoss的7.0.x在我的测试环境
这里是我的webpack.config.js
const webpack = require('webpack');
const autoprefixer = require('autoprefixer');
module.exports = {
cache: true,
entry: [
'webpack-dev-server/client?http://localhost:8008',
'webpack/hot/only-dev-server',
'babel-polyfill',
'./src/index.js',
],
module: {
loaders: [
{
test: /\.jsx?$/,
exclude: /node_modules/,
loader: 'react-hot!babel',
},
{
test: /\.(jpe?g|png|gif|svg)$/i,
loaders: [
'url?limit=2048',
'img',
],
},
{
test: /\.(woff|woff2|eot|ttf)$/,
loader: 'url-loader?limit=2048',
},
{
test: /\.scss$/,
loaders: ['style', 'css', 'postcss-loader', 'sass'],
},
],
},
resolve: {
extensions: ['', '.js', '.jsx'],
},
output: {
path:`${__dirname}/(spring-boot-app-url/resources/static`,
publicPath: '/publicpath/',
filename: 'bundle.js',
},
devServer: {
port: 8008,
contentBase: './dist',
historyApiFallback: true,
hot: true,
proxy: {
.....(proxy config)
},
},
},
},
postcss:() => {
return [autoprefixer];
},
plugins: [
new webpack.HotModuleReplacementPlugin(),
new webpack.optimize.UglifyJsPlugin(),
new webpack.optimize.DedupePlugin(),
new webpack.DefinePlugin({
'process.env': {
'NODE_ENV': JSON.stringify('production'),
},
}),
],
};
在我的春天
我有一些春天的安全配置:
@Override
protected void configure(HttpSecurity httpSecurity) throws Exception {
httpSecurity
.csrf().disable()
.authorizeRequests()
.antMatchers(TOKEN_NAME).permitAll() // API
...(antMatchers)
.and()
.authorizeRequests()
.antMatchers(TOKEN_BASED_AUTH_ENTRY_POINT).permitAll();
httpSecurity
.addFilterBefore(authenticationTokenFilterBean(), UsernamePasswordAuthenticationFilter.class);
httpSecurity.headers().cacheControl().disable();
}
这里是从我的网络标签中的请求首部:
Accept:*/*
Accept-Encoding:gzip, deflate, sdch, br
Accept-Language:fr-FR,fr;q=0.8,en-US;q=0.6,en;q=0.4
Connection:keep-alive
Host:*****
Referer:https://****/appname/
User-Agent:Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/54.0.2840.99 Safari/537.36
这里是从网络选项卡中的标题输入反应:
Accept-Ranges:bytes
Cache-Control:max-age=3600
Connection:keep-alive
Content-Length:1248915
Content-Type:application/javascript; charset=UTF-8
Date:Mon, 05 Dec 2016 12:56:47 GMT
Last-Modified:Mon, 05 Dec 2016 09:08:06 GMT
Server:JBoss-EAP/7
Strict-Transport-Security:max-age=31536000 ; includeSubDomains
X-Content-Type-Options:nosniff
X-Frame-Options:DENY
X-Powered-By:Undertow/1
X-XSS-Protection:1; mode=block
当我与HTTP URL运行它,头请求没有任何缓存控制。 关于如何缓存bundle.js文件的任何想法,即使我使用https运行我的应用程序?
谢谢
,你能否告诉我们这个特定资源的请求和响应HTTP标头? –
我添加了https请求和响应头,它们和http之间的区别在于为https添加了Cache-control。 – METTAIBI
你是如何得到这些标题的?您是否在浏览器中设置了“禁用缓存”选项,或者是否使用“Ctrl + R”刷新了浏览器选项卡?如果不是,'Cache-Control:max-age = 0'意味着问题来自您的客户端并且服务器的行为正常。 –