Apache Mod_Deflate and Flash SWF Files Don’t Like Each Other

August 4, 2009

Recently I was working on a Flex project and upon completion and successful QA, I deployed it on a clients server for use. After embedding the SWF file and adding the data.xml that populated the flash application, I could not load the application in Firefox or IE. Several refreshes would load the application occasionally, however most of the time I just had a grey box.

So while troubleshooting using Firebug, I realized that the clients server I had deployed on was using Apache 2.2.11 with Mod_Deflate enabled, a method commonly used to compress up to 70% of data transfered over the wire to speed page loads. I then had a flash back on reading an article about issues with compression of SWF’s, and upon further investigation of the clients Apache configuration file I saw SWF was not excluded from compression via Mod_Deflate.

Mod_Deflate was compressing SWF files sending them with chunked transfer encoding to the browser. It appears the last part of the chunk was being missed by the browser. By refreshing the browser cache it sometimes filled in the missing chunk, and displayed the application.

So I added SWF to the list of files not to compress via Mod_Deflate and the application worked perfectly everytime.

Below is the section I added the SWF exclusion:

BEFORE:

<Location />
# Insert filter
SetOutputFilter DEFLATE
 
# Netscape 4.x has some problems...
BrowserMatch ^Mozilla/4 gzip-only-text/html
 
# Netscape 4.06-4.08 have some more problems
BrowserMatch ^Mozilla/4\.0[678] no-gzip
 
# MSIE masquerades as Netscape, but it is fine
BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
 
# Don't compress images and other uncompressible content
SetEnvIfNoCase Request_URI \
 \.(?:gif|jpe?g|png|rar|zip|exe|flv|mov|wma|mp3|avi|mp?g)$ no-gzip dont-vary
 
# Make sure proxies don't deliver the wrong content
Header append Vary User-Agent env=!dont-vary
</Location>

AFTER:

 
<Location />
# Insert filter
SetOutputFilter DEFLATE
 
# Netscape 4.x has some problems...
BrowserMatch ^Mozilla/4 gzip-only-text/html
 
# Netscape 4.06-4.08 have some more problems
BrowserMatch ^Mozilla/4\.0[678] no-gzip
 
# MSIE masquerades as Netscape, but it is fine
BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
 
# Don't compress images and other uncompressible content
SetEnvIfNoCase Request_URI \
 \.(?:gif|jpe?g|png|rar|zip|exe|flv|mov|wma|mp3|avi|swf|mp?g)$ no-gzip dont-vary
 
# Make sure proxies don't deliver the wrong content
Header append Vary User-Agent env=!dont-vary
</Location>

Comments for “Apache Mod_Deflate and Flash SWF Files Don’t Like Each Other”

  1. I just ran into this problem myself. I spent four days debugging until I finally realized what was going on.

    I’m surprised this isn’t documented more, your’s is only one of two sites I could find that even mention it.

  2. E-TARD commented on July 12, 2010

    Thanks for the info
    I was thinking of adding swf to gzip in the hopes it would speed things up

    so does compressing gif|jpe?g|png|rar|zip|exe|flv|mov|wma|mp3|avi|swf really not help at all

  3. Thanks for this info. I’ve been experiencing this issue with preloading Adobe Captivate e-learning lessons (SWFs). There is a huge latency before the file begins playing, no matter what you set the preloader percentage to. However, in my case I do not have access to the Apache server HTTP.conf file to alter the settings across the server because I’m using a hosting service. Is there a way you know of to add similar exclusions to a .htaccess file on my website so that mod_deflate ignores flash SWF files?

  4. Hi Rod I don’t think you can use a .htaccess file for the exclusions but I could be wrong. I just have never done it that way. Part of the reason I like to have root on a dedicated server, so that I can have a more custom apache build.

  5. John Richter commented on April 22, 2011

    I just talked with my hosting company and they do not seem to be willing to change the http.conf file because it affects every single account they have (gee, so they want ALL of their customers to have a problem?!)

    They said that a change could be made with an .htaccess file, but have no info on how to make that happen.

    I’m not a programmer. If anyone has any suggestions that would be awesome.

  6. Andy commented on January 20, 2012

    Awesome, exactly what I was looking for. Thanks!

  7. Bela commented on June 20, 2012

    Flash files per se are not compressed but all elements contained as resources are compressed (and there’s also some compression applied to the header as well). Applying gzip to a flash file (and any other media type for that matter) is not necessary and only causes extra delays in displaying the file as it is uncompressed and then parsed.

    http://www.the-labs.com/MacromediaFlash/SWF-Spec/SWFfileformat.html

  8. kinderale commented on July 3, 2013

    Thanks a lot, i tried many configuration files to exclude swf from gzip, but only this one is working (i don’t know why…)

Leave a Reply