Page Speed Optimization Code
Create projectName
- Gruntfile.js
- Package.json
- projectName folder
Commends :-
Install node latest version
Npm install
- Npm install grunt-tinyimg --save-dev
- Npm install grunt-contrib-htmlmin --save-dev
- Npm install grunt-contrib-cssmin --save-dev
- Npm install grunt-contrib-concat --save-dev
- Npm install grunt-contrib-uglify --save-dev
- Npm install grunt-contrib-compress --save-dev
Gruntfile.js
-----------------
module.exports = function (grunt) {
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
tinyimg: {
dynamic: {
files: [{
expand: true,
cwd: 'projectname/img/',
src: ['**/*.{png,gif,jpg,jpeg,svg}'],
dest: 'production/projectname/img/'
}]
}
},
cssmin: {
options: {
shorthandCompacting: false,
roundingPrecision: -1
},
target: {
files: {
'production/projectname/css/styles.min.css': ['projectname/css/style.css']
}
}
},
htmlmin: { // Task
dist: { // Target
options: { // Target options
removeComments: true,
collapseWhitespace: true
},
files: { // Dictionary of files
'production/projectname/index.html': 'projectname/index.html'
}
}
},
concat: {
options: {
separator: ';',
stripBanners: true,
banner: '/*! <%= pkg.name %> - v<%= pkg.version %> - <%= pkg.author %>-' +
'<%= grunt.template.today("yyyy-mm-dd") %> */',
},
dist: {
src: ['projectname/js/custom.js', 'projectname/js/custom1.js'],
dest: 'projectname/js/custom_include.js',
},
},
uglify: {
my_target: {
files: {
'production/projectname/js/custom_include.min.js': ['projectname/js/custom_include.js']
}
}
},
// gzip assets 1-to-1 for production
compress: {
main: {
options: {
mode: 'gzip'
},
expand: true,
cwd: 'prod/',
src: ['**/*'],
dest: 'host_production/'
}
}
});
grunt.loadNpmTasks('grunt-tinyimg');
grunt.loadNpmTasks('grunt-contrib-htmlmin');
grunt.loadNpmTasks('grunt-uncss');
grunt.loadNpmTasks('grunt-contrib-cssmin');
grunt.loadNpmTasks('grunt-contrib-concat');
grunt.loadNpmTasks('grunt-contrib-uglify');
grunt.loadNpmTasks('grunt-contrib-compress');
};
Package.js
-----------------
{
"name": "SampleProject",
"version": "1",
"description": "minified",
"main": "Gruntfile.js",
"author": "authorName",
"devDependencies": {
"grunt": "^0.4.5",
"grunt-contrib-compress": "^1.4.1",
"grunt-contrib-concat": "^1.0.1",
"grunt-contrib-cssmin": "^0.12.3",
"grunt-contrib-htmlmin": "^2.3.0",
"grunt-contrib-uglify": "^0.9.1",
"grunt-tinyimg": "^1.0.0",
"jit-grunt": "^0.9.1"
}
}

Comments
Post a Comment