Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

asset_timestamp is making it impossible to debug produced JS (i.e. inserting breakpoints) #13

Open
stefanoverna opened this issue Mar 2, 2013 · 1 comment

Comments

@stefanoverna
Copy link

Hey, thanks for this little awesome gem.
The only problem is that:

<%= javascript_include_tag "application" %>

is producing a different URL every time I reload the page based on the timestamp, ie.

<script src="/assets/application.js?1362216894" type="text/javascript"></script>
<script src="/assets/application.js?1362216895" type="text/javascript"></script>
...

This is due to the asset_timestamp method in Padrino:

      # Returns the timestamp mtime for an asset
      #
      # @example
      #   asset_timestamp("some/path/to/file.png") => "?154543678"
      #   asset_timestamp("/some/absolute/path.png", true) => nil
      #
      def asset_timestamp(file_path, absolute=false)
        return nil if file_path =~ /\?/ || (self.class.respond_to?(:asset_stamp) && !self.class.asset_stamp)
        public_file_path = Padrino.root("public", file_path) if Padrino.respond_to?(:root)
        stamp = File.mtime(public_file_path).to_i if public_file_path && File.exist?(public_file_path)
        stamp ||= Time.now.to_i unless absolute
        "?#{stamp}" if stamp
      end

Since sprockets does not produce a final JS, there is no mtime, and Time.now is used.

How do you handle this? :)

@wikimatze
Copy link
Collaborator

Hi @stefanoverna, I checked out Padrino 0.11.4 and searched after the asset_timestamp method and found it under padrino-framework/padrino-helpers/lib/padrino-helpers/asset_tag_helpers.rb. Now it looks like:

      ##
      # Returns the timestamp mtime for an asset.
      #
      # @example
      #   asset_timestamp("some/path/to/file.png") => "?154543678"
      #
      def asset_timestamp(file_path)
        return nil if file_path =~ /\?/ || (self.class.respond_to?(:asset_stamp) && !self.class.asset_stamp)
        public_path = self.class.public_folder if self.class.respond_to?(:public_folder)
        public_path ||= Padrino.root("public") if Padrino.respond_to?(:root)
        public_file_path = File.join(public_path, file_path) if public_path
        stamp = File.mtime(public_file_path).to_i if public_file_path && File.exist?(public_file_path)
        stamp ||= Time.now.to_i
        "?#{stamp}"
      end

Some little things are different now but I'm not quite if you can now debug JavaScript in the way you want, can you test this please?

Cheers

Matthias

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants