0

I have added custom fonts to my website using @font-face, but they reload on each page load/refresh.

In some forums I found a solution about using .htaccess file, but I'm not sure whether I can use it in .net (windows server) or not.

In my web.config file, clientCache is set to Max, but this doesn't affect FONTS.

<staticContent>
  <clientCache cacheControlMode="UseMaxAge" cacheControlMaxAge="7.00:00:00" />
</staticContent>

I'd highly appreciate if you give me a sample code or a working solution.

Many thanks in advance!

Kardo

Kardo
  • 1,658
  • 4
  • 32
  • 52
  • Seems like a duplicate of: http://stackoverflow.com/questions/642954/iis7-cache-control – haim770 Mar 05 '13 at 15:23
  • @haim770, I already have set the UseMaxAge, but it doesn't affect fonts to get cached. – Kardo Mar 05 '13 at 15:46
  • Maybe you need to set up a ttf mime map under static content: http://www.iis.net/configreference/system.webserver/staticcontent/mimemap – ta.speot.is Apr 05 '13 at 02:57
  • Does this answer your question? [IIS7 Cache-Control](https://stackoverflow.com/questions/642954/iis7-cache-control) – Shubh Sep 16 '21 at 07:47

2 Answers2

0

While looking for a solution I came across this question. I have a solution and hope it helps others too.

In the comments you have the suggestion IIS7 Cache Control.

What you need to do is,

1. Create a web.config file with the below content:

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
  <system.webServer>
    <staticContent>
      <clientCache cacheControlMode="UseMaxAge" cacheControlMaxAge="7.00:00:00" />
    </staticContent>
  </system.webServer>
</configuration>

2. Copy this file to your "fonts" directory and done.

This controls how Web clients and proxy servers will cache the content that IIS 7 and later returns. More information from Microsoft Documentation

Shubh
  • 6,693
  • 9
  • 48
  • 83
-1

I ran into the same problem so I changed tactic. I couldn't cache TTF (don't know why) but you CAN cache CSS! So I created a CSS file for my font and included it using base64.

Here's an article about it http://blog.patdavid.net/2012/08/embedding-fonts-with-css-and-base64.html

And to convert your font to base 64: http://base64fonts.com/

Le-roy Staines
  • 2,037
  • 2
  • 22
  • 40