jpillora / grunt-aws

A Grunt interface into the Amazon Node.JS SDK
171 stars 44 forks source link

Specifying Cache Control #29

Closed eat-sleep-code closed 1 year ago

eat-sleep-code commented 9 years ago

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?

eat-sleep-code commented 9 years 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']);
};
eat-sleep-code commented 9 years ago

Anyone?

rrichter commented 9 years ago

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.

aehlke commented 9 years ago

Did you figure this out? Concerning issue to have open...

eat-sleep-code commented 9 years ago

I did not. Right now I am stuck using Cloud Berry Explorer to go in and set the Cache-Control header after every build.

aehlke commented 9 years ago

Yikes. I will give grunt-aws-s3 a short first then, thanks.

VaibhavP17 commented 9 years ago

@aehlke Did you get the solution for this one ? I am stuck... SOS...!!!!

Shishir20 commented 8 years ago

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/**'
    },
aehlke commented 8 years ago

@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 :)