gpt4 book ai didi

ruby-on-rails-3 - 在开发环境中离线运行 Rails 应用程序时,.js 和 .css 文件出现 "Failed to load resource"错误

转载 作者:行者123 更新时间:2023-12-01 06:38:19 28 4
gpt4 key购买 nike

我正在尝试让 Rails 应用程序脱机工作。该应用程序在线时似乎可以正常工作。

在 Chrome 中,当服务器运行时,我在运行应用程序时从 Chrome 控制台看到这一点(部分被剪断)。 :

Document was loaded from Application Cache with manifest
http://localhost:3000/application.manifest
Application Cache Checking event
Application Cache Downloading event
...
Application Cache Progress event (5 of 16) http://localhost:3000/assets/todos.css.scss
Application Cache Progress event (6 of 16) http://localhost:3000/assets/application.css
Application Cache Progress event (7 of 16) http://localhost:3000/assets/todos.js.coffee
Application Cache Progress event (8 of 16) http://localhost:3000/assets/jquery.tmpl.js
Application Cache Progress event (9 of 16) http://localhost:3000/assets/jquery.offline.js
...
Application Cache Progress event (11 of 16) http://localhost:3000/assets/jquery.js
...
Application Cache Progress event (13 of 16) http://localhost:3000/assets/json.js
Application Cache Progress event (14 of 16) http://localhost:3000/assets/scaffolds.css.scss
Application Cache Progress event (15 of 16) http://localhost:3000/assets/application.js
Application Cache Progress event (16 of 16)
Application Cache UpdateReady event

但是,离线时我看到了这一点(同样,有些被剪掉了)。请注意 GET行是加载错误。:
Document was loaded from Application Cache with manifest http://localhost:3000/application.manifest
Application Cache Checking event
GET http://localhost:3000/assets/application.css?body=1 todos:5
GET http://localhost:3000/assets/scaffolds.css?body=1 todos:6
GET http://localhost:3000/assets/todos.css?body=1 todos:7
GET http://localhost:3000/assets/jquery.js?body=1 todos:8
GET http://localhost:3000/assets/jquery_ujs.js?body=1 todos:8
GET http://localhost:3000/assets/jquery.offline.js?body=1 todos:8
GET http://localhost:3000/assets/jquery.tmpl.js?body=1 todos:8
GET http://localhost:3000/assets/json.js?body=1 todos:8
GET http://localhost:3000/assets/offline.js?body=1 todos:8
GET http://localhost:3000/assets/todos.js?body=1 todos:8
GET http://localhost:3000/assets/application.js?body=1 todos:8
Application Cache Error event: Manifest fetch failed (-1) http://localhost:3000/application.manifest

我特别注意到 ?body=1离线时附加到文件名。

环境:
  • 导轨:3.2.8
  • ruby 1.9.3p194
  • WEBrick: 1.3.1
  • MySQL:5.5.28 MySQL 社区服务器
  • Chrome:版本 22.0.1229.94 m
  • 操作系统:Windows 7 企业版 6.1(内部版本 7601:Service Pack 1)

  • gem (我认为相关的 gem ):
  • jquery-rails (2.1.3)
  • json (1.7.5, 1.5.4)
  • 机架离线 (0.6.4)
  • 链轮 (2.1.3)

  • 申请 list :
    CACHE MANIFEST
    # ef05db1f746b226b3eb8b3673d65d3585eb8a9e1e35f79a6fc9d90693ff9a569
    404.html
    422.html
    500.html
    index.html
    assets/application.js
    assets/jquery.js
    assets/jquery.offline.js
    assets/jquery.tmpl.js
    assets/json.js
    assets/todos.js.coffee
    assets/application.css
    assets/scaffolds.css.scss
    assets/todos.css.scss

    NETWORK:
    /

    application.html.erb :
    <!DOCTYPE html>
    <html manifest="/application.manifest">
    <head>
    <title>TestOffsite</title>
    <%= stylesheet_link_tag "application", :media => "all" %>
    <%= javascript_include_tag "application" %>
    <%= csrf_meta_tags %>
    </head>
    <body>

    <%= yield %>

    </body>
    </html>

    todos_controller.erb (剪断):
    class TodosController < ApplicationController
    # GET /todos
    # GET /todos.json
    respond_to :html, :json

    def index
    @todos = Todo.all
    respond_with(@todos)
    #respond_to do |format|
    # format.html # index.html.erb
    # format.json { render json: @todos }
    #end
    end
    ...

    manifest.yml 的内容 :
    ---
    rails.png: rails-be8732dac73d845ac5b142c8fb5f9fb0.png
    application.js: application-39fb9cbdc400e6885a41059ea60f3851.js
    application.css: application-0149f820dbdd285aa65e241569d8c256.css

    任何帮助深表感谢。

    最佳答案

    为了让我的本地环境从 app/assets/* 目录而不是/public/assets 中提取 Assets ,我必须在 development.rb 中设置以下内容:

      # Don't fallback to assets pipeline if a precompiled asset is missed (ON for Heroku)
    # config.assets.compile = true

    # Compress JavaScripts and CSS (ON for Heroku)
    # config.assets.compress = true

    # Generate digests for assets URLs (ON for Heroku)
    # config.assets.digest = true

    # Don't pull public assets in development mode - remove to check CDN/S3 assets (OFF for Heroku)
    config.assets.prefix = "/dev-assets"

    # Enable serving of images, stylesheets, and JavaScripts from an asset server (ON for Heroku)
    # config.action_controller.asset_host = "//#{ENV['FOG_DIRECTORY']}.s3.amazonaws.com"
    # config.action_controller.asset_host = "http://cdn%d.mydomain.com"

    当它准备好在我的 Heroku 登台服务器上运行时,它看起来像这样:
      # Don't fallback to assets pipeline if a precompiled asset is missed (ON for Heroku)
    config.assets.compile = true

    # Compress JavaScripts and CSS (ON for Heroku)
    config.assets.compress = true

    # Generate digests for assets URLs (ON for Heroku)
    config.assets.digest = true

    # Don't pull public assets in development mode - remove to check CDN/S3 assets (OFF for Heroku)
    # config.assets.prefix = "/dev-assets"

    # Enable serving of images, stylesheets, and JavaScripts from an asset server (ON for Heroku)
    # config.action_controller.asset_host = "//#{ENV['FOG_DIRECTORY']}.s3.amazonaws.com"
    config.action_controller.asset_host = "http://cdn%d.mydomain.com"

    我经常这样做 - 来回翻转它们 - 因为有时我想检查以确保 CloudFront 正在为新推送的 Assets 提供服务,有时我只想要本地速度和开发我的 CSS 或 JS 文件的能力。

    关于ruby-on-rails-3 - 在开发环境中离线运行 Rails 应用程序时,.js 和 .css 文件出现 "Failed to load resource"错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13021586/

    28 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com