Add query parameter for cache control.

TODO: PluginAssetsServlet should add Last-Modified header instead of Cache-Control header.
This commit is contained in:
KOUNOIKE Yuusuke
2017-03-14 06:48:35 +09:00
parent 8fa3bf7850
commit 1312276151
10 changed files with 60 additions and 45 deletions

View File

@@ -79,6 +79,16 @@ object helpers extends AvatarImageProvider with LinkConverter with RequestCache
*/ */
def hashDate(date: Date): String = new SimpleDateFormat("yyyyMMddHHmmss").format(date) def hashDate(date: Date): String = new SimpleDateFormat("yyyyMMddHHmmss").format(date)
/**
* java.util.Date of boot timestamp.
*/
val bootDate: Date = new Date()
/**
* hashDate of bootDate for /assets, /plugin-assets
*/
def hashQuery: String = hashDate(bootDate)
/** /**
* Returns singular if count is 1, otherwise plural. * Returns singular if count is 1, otherwise plural.
* If plural is not specified, returns singular + "s" as plural. * If plural is not specified, returns singular + "s" as plural.
@@ -216,6 +226,11 @@ object helpers extends AvatarImageProvider with LinkConverter with RequestCache
*/ */
def assets(implicit context: Context): String = s"${context.path}/assets" def assets(implicit context: Context): String = s"${context.path}/assets"
/**
* Returns the url to the path of assets.
*/
def assets(path: String)(implicit context: Context): String = s"${context.path}/assets${path}?${hashQuery}"
/** /**
* Generates the text link to the account page. * Generates the text link to the account page.
* If user does not exist or disabled, this method returns user name as text without link. * If user does not exist or disabled, this method returns user name as text without link.

View File

@@ -130,8 +130,8 @@
</tr> </tr>
</table> </table>
} }
<script type="text/javascript" src="@helpers.assets/vendors/jsdifflib/difflib.js"></script> <script type="text/javascript" src="@helpers.assets("/vendors/jsdifflib/difflib.js")"></script>
<link href="@helpers.assets/vendors/jsdifflib/diffview.css" type="text/css" rel="stylesheet" /> <link href="@helpers.assets("/vendors/jsdifflib/diffview.css")" type="text/css" rel="stylesheet" />
<script> <script>
$(function(){ $(function(){
@if(showIndex){ @if(showIndex){

View File

@@ -38,8 +38,8 @@
</div> </div>
</div> </div>
</div> </div>
<link href="@helpers.assets/vendors/google-code-prettify/prettify.css" type="text/css" rel="stylesheet"/> <link href="@helpers.assets("/vendors/google-code-prettify/prettify.css")" type="text/css" rel="stylesheet"/>
<script src="@helpers.assets/vendors/google-code-prettify/prettify.js"></script> <script src="@helpers.assets("/vendors/google-code-prettify/prettify.js")"></script>
<script> <script>
$(function(){ $(function(){
@if(elastic){ @if(elastic){
@@ -47,7 +47,7 @@ $(function(){
} }
$('#preview@uid').click(function(){ $('#preview@uid').click(function(){
$('#preview-area@uid').html('<img src="@helpers.assets/common/images/indicator.gif"> Previewing...'); $('#preview-area@uid').html('<img src="@helpers.assets("/common/images/indicator.gif")"> Previewing...');
$.post('@helpers.url(repository)/_preview', { $.post('@helpers.url(repository)/_preview', {
content : $('#content@uid').val(), content : $('#content@uid').val(),
enableWikiLink : @enableWikiLink, enableWikiLink : @enableWikiLink,

View File

@@ -13,7 +13,7 @@
@gitbucket.core.dashboard.html.tab() @gitbucket.core.dashboard.html.tab()
<div class="container"> <div class="container">
<div class="pull-right"> <div class="pull-right">
<a href="@context.path/activities.atom"><img src="@helpers.assets/common/images/feed.png" alt="activities"></a> <a href="@context.path/activities.atom"><img src="@helpers.assets("/common/images/feed.png")" alt="activities"></a>
</div> </div>
@gitbucket.core.helper.html.activities(activities) @gitbucket.core.helper.html.activities(activities)
</div> </div>

View File

@@ -7,42 +7,42 @@
<meta charset="utf-8"> <meta charset="utf-8">
<title>@title</title> <title>@title</title>
<meta http-equiv="X-UA-Compatible" content="IE=edge" /> <meta http-equiv="X-UA-Compatible" content="IE=edge" />
<link rel="icon" href="@helpers.assets/common/images/gitbucket.png" type="image/vnd.microsoft.icon" /> <link rel="icon" href="@helpers.assets("/common/images/gitbucket.png")" type="image/vnd.microsoft.icon" />
<meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta name="viewport" content="width=device-width, initial-scale=1.0">
<link href="@helpers.assets/vendors/bootstrap-3.3.6/css/bootstrap.min.css" rel="stylesheet"> <link href="@helpers.assets("/vendors/bootstrap-3.3.6/css/bootstrap.min.css")" rel="stylesheet">
<link href="@helpers.assets/vendors/octicons-4.2.0/octicons.css" rel="stylesheet"> <link href="@helpers.assets("/vendors/octicons-4.2.0/octicons.css")" rel="stylesheet">
<link href="@helpers.assets/vendors/bootstrap-datetimepicker-4.17.44/css/bootstrap-datetimepicker.min.css" rel="stylesheet"> <link href="@helpers.assets("/vendors/bootstrap-datetimepicker-4.17.44/css/bootstrap-datetimepicker.min.css")" rel="stylesheet">
<link href="@helpers.assets/vendors/colorpicker/css/bootstrap-colorpicker.css" rel="stylesheet"> <link href="@helpers.assets("/vendors/colorpicker/css/bootstrap-colorpicker.css")" rel="stylesheet">
<link href="@helpers.assets/vendors/google-code-prettify/prettify.css" type="text/css" rel="stylesheet"/> <link href="@helpers.assets("/vendors/google-code-prettify/prettify.css")" type="text/css" rel="stylesheet"/>
<link href="@helpers.assets/vendors/facebox/facebox.css" rel="stylesheet"/> <link href="@helpers.assets("/vendors/facebox/facebox.css")" rel="stylesheet"/>
<link href="@helpers.assets/vendors/AdminLTE-2.3.8/css/AdminLTE.min.css" rel="stylesheet"> <link href="@helpers.assets("/vendors/AdminLTE-2.3.8/css/AdminLTE.min.css")" rel="stylesheet">
<link href="@helpers.assets/vendors/AdminLTE-2.3.8/css/skins/skin-blue.min.css" rel="stylesheet"> <link href="@helpers.assets("/vendors/AdminLTE-2.3.8/css/skins/skin-blue.min.css")" rel="stylesheet">
<link href="@helpers.assets/vendors/font-awesome-4.6.3/css/font-awesome.min.css" rel="stylesheet"> <link href="@helpers.assets("/vendors/font-awesome-4.6.3/css/font-awesome.min.css")" rel="stylesheet">
<link href="@helpers.assets/common/css/gitbucket.css" rel="stylesheet"> <link href="@helpers.assets("/common/css/gitbucket.css")" rel="stylesheet">
<script src="@helpers.assets/vendors/jquery/jquery-1.12.2.min.js"></script> <script src="@helpers.assets("/vendors/jquery/jquery-1.12.2.min.js")"></script>
<script src="@helpers.assets/vendors/dropzone/dropzone.js"></script> <script src="@helpers.assets("/vendors/dropzone/dropzone.js")"></script>
<script src="@helpers.assets/common/js/validation.js"></script> <script src="@helpers.assets("/common/js/validation.js")"></script>
<script src="@helpers.assets/common/js/gitbucket.js"></script> <script src="@helpers.assets("/common/js/gitbucket.js")"></script>
<script src="@helpers.assets/vendors/bootstrap-3.3.6/js/bootstrap.js"></script> <script src="@helpers.assets("/vendors/bootstrap-3.3.6/js/bootstrap.js")"></script>
<script src="@helpers.assets/vendors/bootstrap3-typeahead/bootstrap3-typeahead.js"></script> <script src="@helpers.assets("/vendors/bootstrap3-typeahead/bootstrap3-typeahead.js")"></script>
<script src="@helpers.assets/vendors/bootstrap-datetimepicker-4.17.44/js/moment.min.js"></script> <script src="@helpers.assets("/vendors/bootstrap-datetimepicker-4.17.44/js/moment.min.js")"></script>
<script src="@helpers.assets/vendors/bootstrap-datetimepicker-4.17.44/js/bootstrap-datetimepicker.min.js"></script> <script src="@helpers.assets("/vendors/bootstrap-datetimepicker-4.17.44/js/bootstrap-datetimepicker.min.js")"></script>
<script src="@helpers.assets/vendors/colorpicker/js/bootstrap-colorpicker.js"></script> <script src="@helpers.assets("/vendors/colorpicker/js/bootstrap-colorpicker.js")"></script>
<script src="@helpers.assets/vendors/google-code-prettify/prettify.js"></script> <script src="@helpers.assets("/vendors/google-code-prettify/prettify.js")"></script>
<script src="@helpers.assets/vendors/elastic/jquery.elastic.source.js"></script> <script src="@helpers.assets("/vendors/elastic/jquery.elastic.source.js")"></script>
<script src="@helpers.assets/vendors/facebox/facebox.js"></script> <script src="@helpers.assets("/vendors/facebox/facebox.js")"></script>
<script src="@helpers.assets/vendors/jquery-hotkeys/jquery.hotkeys.js"></script> <script src="@helpers.assets("/vendors/jquery-hotkeys/jquery.hotkeys.js")"></script>
<script src="@helpers.assets/vendors/jquery-textcomplete-1.6.2/jquery.textcomplete.js"></script> <script src="@helpers.assets("/vendors/jquery-textcomplete-1.6.2/jquery.textcomplete.js")"></script>
@repository.map { repository => @repository.map { repository =>
<meta name="go-import" content="@context.baseUrl.replaceFirst("^https?://", "")/@repository.owner/@repository.name git @repository.httpUrl" /> <meta name="go-import" content="@context.baseUrl.replaceFirst("^https?://", "")/@repository.owner/@repository.name git @repository.httpUrl" />
} }
<script src="@helpers.assets/vendors/AdminLTE-2.3.8/js/app.js" type="text/javascript"></script> <script src="@helpers.assets("/vendors/AdminLTE-2.3.8/js/app.js")" type="text/javascript"></script>
</head> </head>
<body class="skin-blue page-load @if(context.sidebarCollapse){sidebar-collapse}"> <body class="skin-blue page-load @if(context.sidebarCollapse){sidebar-collapse}">
<div class="wrapper"> <div class="wrapper">
<header class="main-header"> <header class="main-header">
<a href="@context.path/" class="logo"> <a href="@context.path/" class="logo">
<img src="@helpers.assets/common/images/gitbucket.png" style="width: 24px; height: 24px; display: inline;"/> <img src="@helpers.assets("/common/images/gitbucket.png")" style="width: 24px; height: 24px; display: inline;"/>
GitBucket GitBucket
<span class="header-version">@gitbucket.core.GitBucketCoreModule.getVersions.last.getVersion</span> <span class="header-version">@gitbucket.core.GitBucketCoreModule.getVersions.last.getVersion</span>
</a> </a>

View File

@@ -43,7 +43,7 @@
} }
</div> </div>
<div class="check-conflict" style="display: none;"> <div class="check-conflict" style="display: none;">
<img src="@helpers.assets/common/images/indicator.gif"/> Checking... <img src="@helpers.assets("/common/images/indicator.gif")"/> Checking...
</div> </div>
</div> </div>
@if(commits.nonEmpty && context.loginAccount.isDefined){ @if(commits.nonEmpty && context.loginAccount.isDefined){

View File

@@ -21,7 +21,7 @@
<div class="check-conflict" style="display: none;"> <div class="check-conflict" style="display: none;">
<div class="issue-comment-box" style="background-color: #fbeed5"> <div class="issue-comment-box" style="background-color: #fbeed5">
<div class="box-content"class="issue-content" style="border: 1px solid #c09853; padding: 10px;"> <div class="box-content"class="issue-content" style="border: 1px solid #c09853; padding: 10px;">
<img src="@helpers.assets/common/images/indicator.gif"/> Checking... <img src="@helpers.assets("/common/images/indicator.gif")"/> Checking...
</div> </div>
</div> </div>
</div> </div>
@@ -63,4 +63,4 @@ $(function(){
}); });
} }
}); });
</script> </script>

View File

@@ -50,10 +50,10 @@
</form> </form>
} }
} }
<script type="text/javascript" src="@helpers.assets/vendors/jsdifflib/difflib.js"></script> <script type="text/javascript" src="@helpers.assets("/vendors/jsdifflib/difflib.js")"></script>
<link href="@helpers.assets/vendors/jsdifflib/diffview.css" type="text/css" rel="stylesheet" /> <link href="@helpers.assets("/vendors/jsdifflib/diffview.css")" type="text/css" rel="stylesheet" />
<script> <script>
$(function(){ $(function(){
diffUsingJS('oldText', 'newText', 'diffText', 1); diffUsingJS('oldText', 'newText', 'diffText', 1);
}); });
</script> </script>

View File

@@ -72,9 +72,9 @@
</form> </form>
} }
} }
<script src="@helpers.assets/vendors/ace/ace.js" type="text/javascript" charset="utf-8"></script> <script src="@helpers.assets("/vendors/ace/ace.js")" type="text/javascript" charset="utf-8"></script>
<script type="text/javascript" src="@helpers.assets/vendors/jsdifflib/difflib.js"></script> <script type="text/javascript" src="@helpers.assets("/vendors/jsdifflib/difflib.js")"></script>
<link href="@helpers.assets/vendors/jsdifflib/diffview.css" type="text/css" rel="stylesheet" /> <link href="@helpers.assets("/vendors/jsdifflib/diffview.css")" type="text/css" rel="stylesheet" />
<script> <script>
$(function(){ $(function(){
$('#editor').text($('#initial').val()); $('#editor').text($('#initial').val());
@@ -132,7 +132,7 @@ $(function(){
@if(fileName.map(helpers.isRenderable _).getOrElse(false)) { @if(fileName.map(helpers.isRenderable _).getOrElse(false)) {
// update preview // update preview
$('#preview').html('<img src="@helpers.assets/common/images/indicator.gif"> Previewing...'); $('#preview').html('<img src="@helpers.assets("/common/images/indicator.gif")"> Previewing...');
$.post('@helpers.url(repository)/_preview', { $.post('@helpers.url(repository)/_preview', {
content : editor.getValue(), content : editor.getValue(),
enableWikiLink : false, enableWikiLink : false,

View File

@@ -49,8 +49,8 @@
<script> <script>
$(function(){ $(function(){
$('a[rel*=facebox]').facebox({ $('a[rel*=facebox]').facebox({
'loadingImage': '@helpers.assets/vendors/facebox/loading.gif', 'loadingImage': '@helpers.assets("/vendors/facebox/loading.gif")',
'closeImage': '@helpers.assets/vendors/facebox/closelabel.png' 'closeImage': '@helpers.assets("/vendors/facebox/closelabel.png")'
}); });
$(document).on("click", ".js-fork-owner-select-target", function() { $(document).on("click", ".js-fork-owner-select-target", function() {