Closed eat-sleep-code closed 1 year ago
This definitely is not working.
I cleared my items from the S3 store, and executed my Grunt script. I inspected the headers, and there is no Cache-Control header set at all.
I can successfully set the Cache-Control manually using CloudBerry Explorer, but that kind of throws a monkey wrench in the concept of an automated deployment. Everytime I push a change through Grunt, it loses the Cache-Control header.
Here is my Gruntfile.js
module.exports = function(grunt) {
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
aws: grunt.file.readJSON('aws.json'),
concat: {
options: {
separator: '\n',
stripBanners: {
block: true
}
},
scripts: {
src: [
'scripts/bootstrap.js',
'scripts/bootstrap-select.js',
'scripts/bootbox.js',
'scripts/app.js',
'scripts/jquery.validate.js',
'scripts/additional-methods.js',
'scripts/captcha.js',
'scripts/mail.js',
'scripts/render.js'
],
dest: 'scripts/bundle.js'
},
style: {
src: [
'style/jquery-ui.css',
'style/bootstrap.css',
'style/bootstrap-select.css',
'style/en-us.css'
],
dest: 'style/bundle.css'
}
},
uglify: {
options: {
banner: '/*! <%= grunt.template.today("dd-mm-yyyy") %> */\n',
mangle: {
except: ['jQuery']
}
},
scripts: {
files: {
'scripts/bundle.min.js': 'scripts/bundle.js'
}
}
},
cssmin: {
target: {
files: [{
expand: true,
cwd: 'style',
src: ['bundle.css'],
dest: 'style',
ext: '.min.css'
}]
}
},
s3: {
options: {
accessKeyId: '<%= aws.key %>',
secretAccessKey: '<%= aws.secret %>',
bucket: '<%= aws.bucket %>',
region: '<%= aws.region %>',
access: 'public-read',
gzip: true
},
upload: {
headers: {
CacheControl: 2592000,
Expires: new Date(Date.now() + 2592000000).toUTCString()
},
cwd: ".",
src: "**"
}
}
});
grunt.loadNpmTasks('grunt-contrib-uglify');
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.loadNpmTasks('grunt-contrib-concat');
grunt.loadNpmTasks('grunt-contrib-cssmin');
grunt.loadNpmTasks('grunt-aws');
grunt.registerTask('default', ['concat', 'uglify', 'cssmin', 's3']);
};
Anyone?
Using cache-control only works for me:
page: {
options: {
headers: {
CacheControl: 630720000
}
},
cwd: "dist/",
src: "**"
}
I use google page speed for verification. Hope this helps.
Did you figure this out? Concerning issue to have open...
I did not. Right now I am stuck using Cloud Berry Explorer to go in and set the Cache-Control header after every build.
Yikes. I will give grunt-aws-s3
a short first then, thanks.
@aehlke Did you get the solution for this one ? I am stuck... SOS...!!!!
Same here. I'm trying this. Din't work.
longTym: {
options: {
headers: {
CacheControl: 'max-age=900, public, must-revalidate'
}
},
src : '<%=pkg.deployPath%><%=pkg.name%>/<%=pkg.version%>/js/**'
},
@VaibhavP17 We're simply using awscli
or one of the other CLI tools now, via grunt-shell
etc., instead of trying to find and use a grunt-specific plugin. Not every tool needs its own grunt plugin, after all :)
I have the following, but it doesn't appear that the Cache-Control and Expires headers are actually being set on the files in S3.
s3: { options: { accessKeyId: '<%= aws.key %>', secretAccessKey: '<%= aws.secret %>', bucket: '<%= aws.bucket %>', region: '<%= aws.region %>', access: 'public-read' }, upload: { headers: { CacheControl: 604800, Expires: new Date(Date.now() + 604800000).toUTCString() }, cwd: ".", src: "**" } }
When I inspect the file in Chrome (for example: https://s3-us-west-2.amazonaws.com/sitecorearizona.org/scripts/bundle.min.js ) I do not see either header included in the response?