1

Is it necessary to handle favicon.ico separately like Google Developers Cloud Playground:

- url: /favicon\.ico
  static_files: favicon.ico
  upload: favicon\.ico

If so, why not:

- url: /favicon.ico
  static_files: favicon.ico
  upload: favicon.ico


In my real app.yaml I didn't handle favicon.ico separately and it seems to be working:

application: myAppName
version: 1
runtime: python27
api_version: 1
threadsafe: true

handlers:
- url: /
  static_files: website/index.html
  upload: website/index.html

- url: /
  static_dir: website

Inside the website folder I have the following:

  • images_folder
  • favicon.ico
  • index.html
7
  • I have never seen the need to use regex in an explicit handler like favicon. I use the simpler, second variation. Are you sure you can access favicon without a handler? Perhaps your browser is using the cached version? Rarely are static files all at the root level, so handlers are necessary.
    – GAEfan
    Commented Jun 28, 2014 at 14:48
  • "Are you sure you can access favicon without a handler?" Yes! "Rarely are static files all at the root level" At the root level I just have the main/index page, plus the favicon, that is usually kept there.
    – Mori
    Commented Jun 28, 2014 at 15:35
  • I think it's cached in your browser. I just tested it, and I get a 404 for favicon.ico, when it does not have a handler.
    – GAEfan
    Commented Jun 28, 2014 at 15:51
  • "I think it's cached in your browser." I tried it in 4 major browsers in Windows as well as 5 major browsers in Mac: no probs!
    – Mori
    Commented Jun 28, 2014 at 15:53
  • The 2nd url handler should never get hit, as the first handles them all.
    – GAEfan
    Commented Jun 28, 2014 at 15:55

3 Answers 3

1

Looks like you're trying to serve a static site. I would use:

application: myAppName
version: 1
runtime: python27
api_version: 1
threadsafe: true

handlers:
- url: /images
  static_dir: website/images_folder/

- url: /.+     # this should handle the favicon.ico, but see below
  static_dir: website/

- url: /
  static_files: website/index.html
  upload: website/index.html

Although, I'd prefer to explicitly state the favicon handler:

- url: /favicon.ico
  static_files: favicon.ico
  upload: favicon.ico

And, really, I would put the favicon in the images_folder, for a tidier dev environment, but that's a separate discussion.

1

This isn't about your whole question, just a specific part (when you ask why not remove the backslashes in your favicon.ico). The url configuration is actually a regex (see here). The reason you have backslashes is that a "." in regex means any character. The reason this still works is that a literal "." will match something that matches any character. The backslash "escapes" the "." (turns it into a literal "." rather than any character). You will find that without the "\" it would match, for example, "faviconaico". While this would very rarely be an actual problem, it is good practice to escape any literal characters.

-1

It is not necessary to handle requests for favicon.ico separately with their own handler in the app.yaml. This is merely a convention since favicons are the most commonly requested icons and generally requested by default on modern browsers.

A generic handler for all .ico files could be used instead but given the somewhat exceptional nature of favicon.ico with default requests from browsers, it's quite common to use a unique handler.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.