Rails 5缓存控件在heroku中不起作用

时间:2016-10-15 21:28:48

标签: ruby-on-rails heroku cache-control

我正在我的应用程序中设置CDN,并根据Rails 5中的新标准设置<!DOCTYPE html> <html> <head> <title>Hangman</title> </head> <body> <h1>Hangman</h1> <script> // array of words var words = [ "trajectory", "symphony", "desire", "antfarm", "dancer", "happiness", "positioning", "hobbit", "obituary", "cheetah", "sunrise", "antithesis", "wrong", "diamonds", "partnership", "oblique", "sanctuary"]; // pick a random word var word = words[Math.floor(Math.random() * words.length)]; // set up the answer array var answerArray = []; for (var i = 0; i < word.length; i++) { answerArray[i] = "_"; } var remainingLetters = word.length; //amount of guesses var guessNumber = 5; //the game loop while (remainingLetters > 0 && guessNumber > 0) { //show the player their progress alert("Your word is " + answerArray.join(" ") + "and you have " +guessNumber+ " guesses left"); //get a guess from player var guess = prompt("Guess a letter, or click cancel to stop playing."); if (guess === null) { //exit the loop alert("Ok you can quit"); break; } else if (guess.length !== 1) { alert("Please enter a single letter."); } else //update the game state with the guess for (var j = 0; j < word.length; j++) { if (word[j] === guess) { answerArray[j] = guess; remainingLetters--; } } else { guessNumber--; } } //end game loop //alert to congratulate player alert(answerArray.join(" ")); alert("Good job! The answer was " + word); </script> </body> </html>

cache-control

但是当我将应用程序部署到Heroku时,它表明我没有使用新标准:

  

弃用警告:不推荐使用config.public_file_server.headers = { 'Cache-Control' => 'public, max-age = 31536000',     'Expires' => "# {1.year.from_now.to_formatted_s (: rfc822)}" } ,将在Rails 5.1中删除。       请改用config.static_cache_control。       (从/app/config/application.rb:14调用)

当我查看页面响应标头未应用config.public_file_server.headers = { 'Cache-Control' => 'public, max-age=604800' }来设置

Image link

2 个答案:

答案 0 :(得分:0)

此问题中是否仅缺少哈希值之间的逗号,还是在您的配置中?试试这个:

config.public_file_server.headers = {
  'Cache-Control' => 'public, max-age = 31536000',
  'Expires' => "# {1.year.from_now.to_formatted_s (: rfc822)}"
}

答案 1 :(得分:0)

我找到了解决这个问题的解决方案https://github.com/romanbsd/heroku-deflater/issues/26,问题出在gem heroku deflater