Skip to content

Commit 5c5b998

Browse files
committed
Asset location refactor to allow for more caching
- Added new htaccess options for Expires and Cache-Control headers - Removed Etag headers - Moved all production assets to be prefixed with the version as a path
1 parent 3ef2bfa commit 5c5b998

File tree

10 files changed

+90
-37
lines changed

10 files changed

+90
-37
lines changed

.htaccess

Lines changed: 57 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,57 @@
1-
RewriteEngine On
2-
3-
#Legacy Rewrites
4-
RewriteCond %{QUERY_STRING} ^id=(.*)$ [NC]
5-
RewriteRule ^schedule.php$ /schedule/%1? [NC,L,R=302]
6-
7-
8-
# Let old ScheduleMaker handle Resig's schedules for now
9-
#RewriteCond %{QUERY_STRING} ^mode=old&id=(.*)$ [NC]
10-
RewriteRule ^schedule.php$ http://schedule-old.csh.rit.edu/schedule.php [NC,L,R=302]
11-
12-
RewriteCond %{HTTP:Accept} application/json [NC]
13-
RewriteRule ^(schedule|generate|entity|search|status|rmp)(?:/([^/]*))*$ api/$1.php [L]
14-
RewriteRule ^schedule/[^/]*/ical$ api/schedule.php [L]
15-
16-
17-
# Don't rewrite files or directories
18-
RewriteCond %{REQUEST_FILENAME} -f [OR]
19-
RewriteCond %{REQUEST_FILENAME} -d
20-
RewriteRule ^ - [L]
21-
22-
23-
# Rewrite everything else to index.html to allow html5 state links
24-
RewriteRule ^ index.php [L]
1+
# COMPRESSION
2+
<IfModule mod_deflate.c>
3+
AddOutputFilterByType DEFLATE text/text text/html text/plain text/xml text/css application/x-javascript application/javascript application/json
4+
</IfModule>
5+
6+
# REWRITES
7+
<IfModule mod_rewrite.c>
8+
RewriteEngine On
9+
10+
# Let the old ScheduleMaker handle Resig's schedules for now
11+
#RewriteCond %{QUERY_STRING} ^mode=old&id=(.*)$ [NC]
12+
RewriteRule ^schedule.php$ http://schedule-old.csh.rit.edu/schedule.php [NC,L,R=302]
13+
14+
# Legacy Rewrites from previous version
15+
RewriteCond %{QUERY_STRING} ^id=(.*)$ [NC]
16+
RewriteRule ^schedule.php$ /schedule/%1? [NC,L,R=302]
17+
RewriteRule ^(generate|roulette|search|status).php$ /$1 [R=302,L]
18+
19+
# Rewrite any request that wants json to the api directory
20+
RewriteCond %{HTTP:Accept} application/json [NC]
21+
RewriteRule ^(schedule|generate|entity|search|status|rmp)(?:/([^/]*))*$ api/$1.php [L]
22+
RewriteRule ^schedule/[^/]*/ical$ api/schedule.php [L]
23+
24+
# Don't rewrite files or directories
25+
RewriteCond %{REQUEST_FILENAME} -f [OR]
26+
RewriteCond %{REQUEST_FILENAME} -d
27+
RewriteRule ^ - [L]
28+
29+
# Rewrite everything else to index.html to allow html5 state links
30+
RewriteRule ^ index.php [L]
31+
</IfModule>
32+
33+
# CACHING
34+
35+
# Set max-age one year in the future for all static assets
36+
<IfModule mod_headers.c>
37+
# Allow caching for all assets
38+
<FilesMatch "(.*)\.(js|css|png|jpg|html)$">
39+
Header set Cache-Control "max-age=29030400, public"
40+
Header unset ETag
41+
FileETag None
42+
</FilesMatch>
43+
</IfModule>
44+
45+
# Cache Everything, set their expiration date one year in the future
46+
<IfModule mod_expires.c>
47+
ExpiresActive On
48+
ExpiresDefault A300
49+
ExpiresByType image/x-icon A29030400
50+
ExpiresByType application/javascript A29030400
51+
ExpiresByType text/css A29030400
52+
ExpiresByType image/gif A29030400
53+
ExpiresByType image/png A29030400
54+
ExpiresByType image/jpeg A29030400
55+
ExpiresByType text/plain A29030400
56+
ExpiresByType text/html A29030400
57+
</IfModule>
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
angular.module('sm').directive("courseCart", function() {
22
return {
33
restrict: 'A',
4-
templateUrl: '/assets/prod/modules/sm/App/templates/cart.min.html'
4+
templateUrl: '<%=modulePath%>App/templates/cart.min.html'
55
};
66
});
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
angular.module('sm').directive("scheduleCourse", function(){
22
return {
33
restrict: "C",
4-
templateUrl: '/assets/prod/modules/sm/Generate/templates/courseselect.min.html',
4+
templateUrl: '<%=modulePath%>Generate/templates/courseselect.min.html',
55
};
66
});

assets/src/modules/sm/Schedule/controllers/SchedulePrintController.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ angular.module('sm').controller("SchedulePrintController", function($scope, $loc
4444

4545
localStorage.setItem("reloadSchedule", null);
4646

47-
$scope.print = window.print.bind(window);
47+
$scope.printFn = window.print.bind(window);
4848

4949
$scope.globalUI.layoutClass = "print";
5050
});

assets/src/modules/sm/Schedule/directives/scheduleDirective.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ angular.module('sm').directive('schedule', function($timeout, $filter) {
182182

183183
return {
184184
restrict: 'A',
185-
templateUrl: '/assets/prod/modules/sm/Schedule/templates/scheduleitem.min.html',
185+
templateUrl: '<%=modulePath%>Schedule/templates/scheduleitem.min.html',
186186
link: {
187187
pre: function(scope, elm, attrs) {
188188
scope.scheduleController = new Schedule(scope);

assets/src/modules/sm/Schedule/templates/schedule.print.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ <h3 class="panel-title">
2525
</div>
2626
</div>
2727
<div class="col-sm-2">
28-
<button ng-click="print()" type="button" class="btn btn-info btn-block">
28+
<button ng-click="printFn()" type="button" class="btn btn-info btn-block">
2929
<i class="fa fa-print"></i> Print
3030
</button>
3131
</div>

assets/src/modules/sm/app.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ angular.module('sm', ['ngAnimate', 'ngSanitize', 'ui.router'])
1313

1414
$urlRouterProvider.otherwise("/404");
1515

16-
var tplBase = '/assets/prod/modules/sm/';
16+
var tplBase = '<%=modulePath%>';
1717

1818
var tplPath = function(submodule, name) {
1919
return tplBase + submodule + '/templates/' + name + '.min.html';

gulpfile.js

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,19 @@
1+
// Get the version info
2+
var pkg = require('./package.json');
3+
if(!pkg.version) {
4+
console.error("No version information in package.json.");
5+
proccess.exit();
6+
}
7+
8+
var assetsRoot = {
9+
src: 'assets/src/',
10+
dest: 'assets/prod/'
11+
}
12+
113
// Set up core routes
214
var modulesRoot = {
3-
src: 'assets/src/modules/',
4-
dest: 'assets/prod/modules/'
15+
src: assetsRoot.src + 'modules/',
16+
dest: assetsRoot.dest + pkg.version + '/modules/'
517
};
618

719
var assetModuleList = {
@@ -83,6 +95,7 @@ var sourcemaps = require('gulp-sourcemaps');
8395
var replace = require('gulp-replace');
8496
var es = require('event-stream');
8597
var minifyCSS = require('gulp-minify-css');
98+
var template = require('gulp-template');
8699

87100
// Define Tasks
88101
gulp.task('templates', function() {
@@ -105,6 +118,7 @@ gulp.task('templates', function() {
105118
gulp.task('scripts', function() {
106119
var mapped = doFor('scripts', function(scriptPaths) {
107120
return gulp.src(scriptPaths.src)
121+
.pipe(template({modulePath: scriptPaths.dest}))
108122
.pipe(ngmin())
109123
.pipe(concat('dist.js'))
110124
.pipe(gulp.dest(scriptPaths.dest))
@@ -152,6 +166,11 @@ gulp.task('clean', function() {
152166
.pipe(clean());
153167
});
154168

169+
gulp.task('cleanAll', function() {
170+
return gulp.src(assetsRoot.dest, {read: false})
171+
.pipe(clean());
172+
});
173+
155174
gulp.task('build', ['clean'], function() {
156175
return gulp.start('scripts', 'templates', 'styles');
157176
});

index.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
<!-- STYLE SHEETS -->
5151
<link rel="stylesheet" href="//brick.a.ssl.fastly.net/Roboto:300,700">
5252
<link rel="stylesheet" href="//netdna.bootstrapcdn.com/font-awesome/4.0.1/css/font-awesome.css">
53-
<link rel="stylesheet" href="<?=$HTTPROOTADDRESS?>assets/prod/modules/sm/dist.css?v=<?=$APP_VERSION?>">
53+
<link rel="stylesheet" href="<?=$HTTPROOTADDRESS?>assets/prod/<?=$APP_VERSION?>/modules/sm/dist.min.css">
5454

5555
<!-- OPEN GRAPH TAGS -->
5656
<meta name="twitter:card" content="photo">
@@ -121,7 +121,7 @@
121121
<script src="//cdnjs.cloudflare.com/ajax/libs/angular.js/1.2.15/angular-animate.min.js"></script>
122122
<script src="//cdnjs.cloudflare.com/ajax/libs/angular.js/1.2.15/angular-sanitize.min.js"></script>
123123
<script src="//cdnjs.cloudflare.com/ajax/libs/angular-ui-router/0.2.8/angular-ui-router.min.js"></script>
124-
<script src="<?=$HTTPROOTADDRESS?>assets/prod/modules/sm/dist.min.js?v=<?=$APP_VERSION?>"></script>
124+
<script src="<?=$HTTPROOTADDRESS?>assets/prod/<?=$APP_VERSION?>/modules/sm/dist.min.js"></script>
125125
</body>
126126
</html>
127127

package.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "schedulemaker",
3-
"version": "3.0.2",
3+
"version": "3.0.3",
44
"private": true,
55
"description": "A course database lookup tool and schedule building web application for use at Rochester Institute of Technology.",
66
"main": "index.php",
@@ -39,7 +39,7 @@
3939
"url": "https://github.com/ComputerScienceHouse/schedulemaker/issues"
4040
},
4141
"config": {
42-
"stateVersion": 1
42+
"stateVersion": 1
4343
},
4444
"homepage": "http://schedule.csh.rit.edu",
4545
"devDependencies": {
@@ -55,6 +55,7 @@
5555
"gulp-sourcemaps": "^0.2.1",
5656
"gulp-replace": "^0.2.0",
5757
"gulp-minify-css": "^0.3.1",
58-
"gulp-htmlmin": "^0.1.2"
58+
"gulp-htmlmin": "^0.1.2",
59+
"gulp-template": "^0.1.1"
5960
}
6061
}

0 commit comments

Comments
 (0)