Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

5.4.0f3 - Troubleshooting gzip compression

Discussion in 'WebGL' started by montag64, Aug 18, 2016.

  1. montag64

    montag64

    Joined:
    Mar 15, 2014
    Posts:
    23
    Hi all,

    I've spent the last few days trying to improve load times on my game and I'm consistently getting the following errors in the console logs on Firefox, Safari, and Chrome across 2 different projects:

    Failed to load resource: the server responded with a status of 404 (Not Found) when trying to access a .mem file (yes, .mem, not memgz the log says) from the Resources folder.

    Decompressed Release/filename.memgz in 156ms. You can remove this delay if you configure your web server to host files using gzip compression.

    I get decompress errors for the memgz, jsgz, and datagz files, which prompted me to start hunting a solution for enabling gzip compression on my Ubuntu 14.04 LTS x64 server running Apache2. I've tried (on two different servers with different configs):

    1) Editing the apache2.conf file in /etc/apache2 to include these two lines:

    Code (config):
    1.  
    2. AddType application/octet-stream .memgz .datagz .unity3dgz
    3. AddType application/javascript .js
    4.  
    2) Adding these lines to the mime.conf file in mods-enabled:

    Code (config):
    1.  
    2. AddType application/octet-stream .mem .data .datagz .memgz
    3. AddType application/x-javascript .jsgz
    4.  
    3) Adding these lines to the deflate.conf file in mods-enabled:

    Code (config):
    1.  
    2. AddOutputFilterByType DEFLATE application/octet-stream
    3. AddOutputFilterByType DEFLATE application/x-gzip
    4.  
    4) Doing 1 and 2 in tandem
    5) Not doing 1 through 4 and creating an .htaccess file like below and placing it in Release

    Code (config):
    1.  
    2. Options +SymLinksIfOwnerMatch<IfModule mod_rewrite.c>
    3.   <IfModule mod_mime.c>
    4.  
    5.     RewriteEngine on
    6.     RewriteCond %{HTTP:Accept-encoding} gzip
    7.     RewriteCond %{REQUEST_FILENAME}gz -f
    8.     RewriteRule ^(.*)\.(js|data|mem|unity3d)$ $1.$2gz [L]
    9.  
    10.     AddEncoding gzip .jsgz
    11.     AddEncoding gzip .datagz
    12.     AddEncoding gzip .memgz
    13.     AddEncoding gzip .unity3dgz
    14.  
    15.   </IfModule>
    16. </IfModule>
    17.  
    6) Trying either placing .htaccess file like below in Release or build root folder:

    Code (config):
    1.  
    2. Options +FollowSymLinks
    3. RewriteEngine on
    4. RewriteBase /var/www/html/fbcanvas_b32/
    5. RewriteCond %{HTTP:Accept-encoding} gzip
    6. RewriteCond %{REQUEST_FILENAME}gz -f
    7. RewriteRule ^(.*)\.js$ $1\.jsgz [L]
    8.  
    9. RewriteCond %{HTTP:Accept-encoding} gzip
    10. RewriteCond %{REQUEST_FILENAME}gz -f
    11. RewriteRule ^(.*)\.data$ $1\.datagz [L]
    12.  
    13. RewriteCond %{HTTP:Accept-encoding} gzip
    14. RewriteCond %{REQUEST_FILENAME}gz -f
    15. RewriteRule ^(.*)\.mem$ $1\.memgz [L]
    16.  
    17. RewriteCond %{HTTP:Accept-encoding} gzip
    18. RewriteCond %{REQUEST_FILENAME}gz -f
    19. RewriteRule ^(.*)\.unity3d$ $1\.unity3dgz [L]
    20.  
    21. AddEncoding gzip .jsgz
    22. AddEncoding gzip .datagz
    23. AddEncoding gzip .memgz
    24. AddEncoding gzip .unity3dgz
    25.  
    In all other aspects, the games seem to play fine.

    I will readily admit I'm not much of a web host admin so my knowledge on Apache is limited. I do have physical access and root access to the server so I'm down for trying out just about anything, but I'm out of ideas for how to get this working. I really don't get why it isn't able to server these gz files decompressed. I can provide builds, links, and apache config files.

    Also, the 404 error concerns me a little when it's looking for the .mem file. The loading seems to stall at that point and that may be contributing to load time slowness.
     
  2. montag64

    montag64

    Joined:
    Mar 15, 2014
    Posts:
    23
    Excuse my derp. I have read Apache docs about 20 times but it never sticks. The .htaccess file worked just fine once I added this to my apache2 config file:

    Code (config):
    1.  
    2. <Directory /var/www/webgl_testbed>
    3. AllowOverrideAll
    4.     Order Allow,Deny
    5.     Allow from all
    6. </Directory>
    7.  
    and stored my webgl build inside that folder. This also took care of the 404 error.

    I guess I won't quit my M$ sysadmin dayjob just yet.

    If I wanted to set this globally for that dir, I would just put the .htaccess contents into the <directory> section of apache2 config like above? That way I don't have to worry about individual .htaccess files in projects?
     
  3. meekrob

    meekrob

    Joined:
    May 14, 2015
    Posts:
    4
    I've run into situations where I have for whatever reason omitted the AllowOverrideAll when it was necessary, causing a frustrating hunt for the cause of some downstream repercussion.

    I think the directive does apply to subdirectories, but I'm not sure. That's easy enough to test.
     
    montag64 likes this.