【问题标题】:Chrome doesn't refresh static JS file when running local development with Google App Engine Flask dev_appserver.py使用 Google App Engine Flask dev_appserver.py 运行本地开发时,Chrome 不会刷新静态 JS 文件
【发布时间】:2017-08-23 16:45:52
【问题描述】:

Chrome 会加载 javascript 文件,但当我更新文件时,更新不会出现在 Chrome 中。我在 Firefox 中尝试过,刷新页面时可以看到 javascript 文件已更新,但在 Chrome 中没有。

我正在使用 Flask,javascript 文件位于静态文件夹中。我的目录如下:

app
-env
-lib
-static
--css
--img
--js <-- there is where my js file is
-templates
--partials
-app.yaml
-main.py
-requirements.txt

我的 app.yaml 文件是:

runtime: python27
api_version: 1
threadsafe: yes    
# Handlers define how to route requests to your application.
handlers:
# This handler tells app engine how to route requests to a WSGI application.
# The script value is in the format <path.to.module>.<wsgi_application>
# where <wsgi_application> is a WSGI application object.
- url: .*  # This regex directs all routes to main.app
  script: main.app

【问题讨论】:

  • 您是否尝试在 chrome 开发工具中禁用缓存(Ctrl + Shift + i)?网络选项卡顶部的复选框用于禁用缓存。必须打开开发工具窗口才能使任何选项起作用。
  • 哇,是的,谢谢@Derek,这完全有效!您应该将其作为官方答案来回答!

标签: javascript google-chrome google-app-engine flask


【解决方案1】:

Ctrl + Shift + i Network Tab > 禁用缓存。

注意:必须打开开发工具才能使选项起作用。

【讨论】:

    【解决方案2】:

    您可以将代码保存在 yourapp/static/js 下的烧瓶中,如中所述 http://exploreflask.com/en/latest/static.html

    修改时使用 javascript 中的版本。

    <script type="text/javascript" src="/static/js/demo.js?v=17"></script>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-08-15
      • 1970-01-01
      • 2014-02-13
      • 2011-07-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多