상세 컨텐츠

본문 제목

엔진 html5 빌드 관련 WebGL(Html5) 사용시 gz, gzip 에러관련 (unreal engine, unity 등등)

WEB/html5

by AlrepondTech 2020. 9. 20. 03:49

본문

반응형

 

=================================

=================================

=================================

 

 

 

출처: http://www.playnexacro.com/index.html#show:article

 

 

소개

웹서비스 최적화 방법중에 하나로 gzip 압축전송이 있습니다.

 

gzip은 파일 압축에 쓰이는 응용 소프트웨어로 GNU zip의 준말이며 무료 소프트웨어이다(출처: 위키백과)

 

이를 사용하기 위해서는 사용하는 브라우저가 지원을 해야합니다.

(브라우저에서 request headers > "Accept-Encoding"에 gzip이 포함되어 있어야 합니다.)

 

 

 

 

 

마찬가지로 서버에서도 gzip으로 전송해야 합니다.

(response headers > "Content-Encodding:gzip")

 

 

 

 

 

 

배경

일반적인 Http Request & Response와 gzip사용시 차이점을 간단히 설명하면 다음과 같습니다.

 

 

 

 

 

1.브라우저에서 index.html을 서버에 요청합니다.

2.서버는 해당 파일을 찾습니다.

3.파일을 요청한 브라우저로 전송합니다(100KB).

4.브라우저는 해당 파일을 표시합니다.

 

 

 

 

 

 

1.브라우저에서 index.html을 서버로 요청시 gzip을 지원한다는 내용을 서버로 전달합니다.

2.서버는 해당 파일을 찾습니다.

3.gzip으로 파일을 압축해서 보냅니다(30KB).

4.브라우저에서 압축된 파일을 풀고 표시합니다.

 

 

 

테스트 환경

  • 서버 OS: Windows7
  • 웹서버: Apache 2.4
  • 브라우저: IE9, 크롬, Firefox, Safari

 

 

환경설정

 

1.Apache httpd.conf 파일 열기
2.LoadModule 영역에서 아래내용에 주석처리 되었으면 해제합니다.

 

LoadModule deflate_module modules/mod_deflate.so
LoadModule headers_module modules/mod_headers.so
LoadModule filter_module modules/mod_filter.so

 

 

3.적당한 위치에 아래 내용을 추가합니다.

<IfModule mod_deflate.c>

AddOutputFilterByType DEFLATE text/plain
AddOutputFilterByType DEFLATE text/html
AddOutputFilterByType DEFLATE text/xml
AddOutputFilterByType DEFLATE text/css
AddOutputFilterByType DEFLATE application/xml
AddOutputFilterByType DEFLATE application/xhtml+xml
AddOutputFilterByType DEFLATE application/rss+xml
AddOutputFilterByType DEFLATE application/javascript
AddOutputFilterByType DEFLATE application/x-javascript

DeflateCompressionLevel 9

BrowserMatch ^Mozilla/4 gzip-only-text/html # Netscape 4.xx에는 HTML만 압축해서 보냄
BrowserMatch ^Mozilla/4\.0[678] no-gzip # Netscape 4.06~4.08에는 압축해서 보내지 않음
BrowserMatch \bMSIE !no-gzip !gzip-only-text/html # 자신을 Mozilla로 알리는 MSIE에는 그대로 압축해서 보냄

##예외 설정
SetEnvIfNoCase Request_URI \.(?:gif|jpe?g|png|bmp|zip|gz|rar|7z)$ no-gzip dont-vary

####로그설정.
##DeflateFilterNote Input instream
##DeflateFilterNote Output outstream
##DeflateFilterNote Ratio ratio
##
##LogFormat '"%r" %{outstream}n/%{instream}n (%{ratio}n%%)' deflate
##CustomLog logs/deflate_log deflate

 

 

4.아파치를 restart 시킨 후 아래 사이트에서 gzip전송이 정상동작하는지 테스트 합니다.
   
   http://www.whatsmyip.org/http-compression-test/

 

 

 

  

위 결과 페이지에서는 특정페이지가 84.5% 절감되고 있습니다.

 

Response Headers 내용은 아래와 같습니다.

                

 

 

 

 

 

※ 3번 "로그설정" 주석해제 후 apache logs폴더에 생성된 deflate_log파일을 보면 압축률을 확인할 수 있습니다.

 


.

"GET /nexacro14lib/framework/SystemBase.js HTTP/1.1" 23987/176486 (13%)
"GET /nexacro14lib/framework/Platform_HTML5.js HTTP/1.1" 18786/138984 (13%)
"GET /nexacro14lib/framework/ErrorDefine.js HTTP/1.1" 4886/18684 (26%)
"GET /nexacro14lib/framework/CssObjs.js HTTP/1.1" 25266/271916 (9%)
"GET /nexacro14lib/framework/BasicObjs.js HTTP/1.1" 9152/50003 (18%)
"GET /nexacro14lib/framework/Platform.js HTTP/1.1" 58726/370077 (15%)
"GET /nexacro14lib/framework/SystemBase_HTML5.js HTTP/1.1" 50261/334443 (15%)
"GET /nexacro14lib/component/CompBase/CompBase.js HTTP/1.1" 28574/167299 (17%)
"GET /nexacro14lib/component/CompBase/CompEventBase.js HTTP/1.1" 17397/255753 (6%)

 

 

 

미리 gzip으로 압축후 사용할 순 없을까?

 

gzip 사용시 단점은 요청시 gzip으로 압축하는 과정으로 인해

서버의 CPU사용량이 gzip을 사용하지 않을 때 보다 증가한다는 것이다.

 

그렇다면 거의 변할 일이 없는 file은 미리 압축해서 사용하는것도 괜찮지 않을까?

 

 

1.gzip으로 압축하기

 

Online YUI Compressor에 접속 후 아래그림 처럼 소스를 gz파일로 변환한다.

① 원하는 소스를 붙여넣기 한다.

② 결과는 "Redirect to gzipped output"을 선택한다.

③ "Compress"버튼을 누르면 잠시 후 파일을 저장할 수 있는 팝업창이 표시된다.

④ "gz"확장자로 원하는 위치와 파일명으로 저장합니다. 

 

 

 



 

 

2.해당 파일을 영역안에 포함시킵니다.

 

<script type="text/javascript" src="./pkg/EcoBasic.js.gz"></script>

 

3.위와 같이 하고 해당페이지에 접속하면 아래처럼 log가 발생하고 정상적으로 load되지 않습니다(크롬).

 

Content-Encoding:gzip
Content-Type:application/x-gzip

Resource interpreted as Script but transferred with MIME type application/x-gzip: "http:// ~ /pkg/EcoBasic.js.gz".

 

 

4.Apache httpd.conf 파일의 LoadModule 영역에서 아래내용에 주석처리 되었으면 해제합니다.

 

​LoadModule dir_module modules/mod_dir.so

 

 

  아래 2줄을 주석처리 되어있으면 해제합니다.

AddEncoding x-compress .Z
AddEncoding x-gzip .gz .tgz

 

 

  아래 2줄을 주석처리 합니다.

#AddType application/x-compress .Z
#AddType application/x-gzip .gz .tgz

 

 

  아래 내용도 추가해야 한다고 나와있었는데 실제로 해보니 적용하지 않아도 처리되었습니다(참고하세요).

  :gz 확장자에 대해서 강제로 content-encoding을 설정하는 내용입니다.

 

# root .
<Directory /~/EcoPkg>
Options Indexes MultiViews FollowSymLinks
#AllowOverride None
#Order deny,allow
#Deny from all
#Allow from 127.0.0.0/255.0.0.0::1/128

AddEncoding gzip gz
<FilesMatch "\.gz$">
ForceType text/plain
Header set Content-Encoding: gzip
FilesMatch>

## <FilesMatch "\.css\.gz$">
## ForceType text/css
## Header set Content-Encoding: gzip
## FilesMatch>
Directory>

 

 

 

5.설정 후 아파치 restart후에 Response Headers를 확인하면 다음과 같습니다.

 

   

 

 

 

 

마치며...

 

※ RUNTIME(2014,9,3,1 버전 기준)에서는 지원하지 않습니다.

 

이미지와 PDF파일은 gzip으로 압축하지 않는다(이미 압축되어 있음). 

 

gzip을 지원하는 브라우저 목록(출처: webmasters.stackexchange.com, 참고: schroepl.net)

  • Netscape 6+ (Netscape 4-5 does, but with some bugs).
  • Internet Explorer 5.5+ (July 2000) and IE 4 if set to HTTP/1.1.
  • Opera 5+ (June 2000)
  • Firefox 0.9.5+ (October 2001)
  • Chrome since forever
  • Safari since forever (as far as I can tell)

 

이 글에서는 Apache httpd.conf 파일을 이용한 예제가 작성되었지만 .htaccess 파일을 이용할 수 도 있다.

 

 

 

변경내역

 

2014.09.15 최초작성. 

 

 

=================================

=================================

=================================

 

 

 

출처: https://varvy.com/pagespeed/enable-compression.html

 

What is Gzip compression?

  • Gzip is a method of compressing files (making them smaller) for faster network transfers.
  • It is also a file format.Compression allows your web server to provide smaller file sizes which load faster for your website users.

Enabling gzip compression is a standard practice. If you are not using it for some reason, your webpages are likely slower than your competitors.

 

 

 

How to enable Gzip compression

  • Compression is enabled via webserver configuration
  • Different web servers have different instructions (explained below)

Here are the most common ways to enable compression including .htaccess, Apache, Nginx, and Litespeed webservers.

Enable compression via .htaccess

For most people reading this, compression is enabled by adding some code to a file called .htaccess on their web host/server. This means going to the file manager (or wherever you go to add or upload files) on your webhost.

The .htaccess file controls many important things for your site. If you are not familiar with the .htaccess file, please read my working with .htaccess article to get some know how before changing it.

The code below should be added to your .htaccess file...

<ifModule mod_gzip.c>
mod_gzip_on Yes
mod_gzip_dechunk Yes
mod_gzip_item_include file .(html?|txt|css|js|php|pl)$
mod_gzip_item_include handler ^cgi-script$
mod_gzip_item_include mime ^text/.*
mod_gzip_item_include mime ^application/x-javascript.*
mod_gzip_item_exclude mime ^image/.*
mod_gzip_item_exclude rspheader ^Content-Encoding:.*gzip.*
</ifModule>

Save the .htaccess file and then refresh your webpage.

Check to see if your compression is working using the Gzip compression tool.

Enable compression on Apache webservers

The instructions and code above will work on Apache. If they are not working there is another way that may work for you. If the above code did not seem to work, remove it from your .htaccess file and try this one instead...

AddOutputFilterByType DEFLATE text/plain
AddOutputFilterByType DEFLATE text/html
AddOutputFilterByType DEFLATE text/xml
AddOutputFilterByType DEFLATE text/css
AddOutputFilterByType DEFLATE application/xml
AddOutputFilterByType DEFLATE application/xhtml+xml
AddOutputFilterByType DEFLATE application/rss+xml
AddOutputFilterByType DEFLATE application/javascript
AddOutputFilterByType DEFLATE application/x-javascript

Enable compression on NGINX webservers

To enable compression in NGINX you will need to add the following code to your config file

gzip on;
gzip_comp_level 2;
gzip_http_version 1.0;
gzip_proxied any;
gzip_min_length 1100;
gzip_buffers 16 8k;
gzip_types text/plain text/html text/css application/x-javascript text/xml application/xml application/xml+rss text/javascript;

# Disable for IE < 6 because there are some known problems
gzip_disable "MSIE [1-6].(?!.*SV1)";

# Add a vary header for downstream proxies to avoid sending cached gzipped files to IE6
gzip_vary on;

Enable compression on Litespeed webservers

The ideal way to enable compression in Litespeed is to do it through the configuration under "tuning". Just go down to "enable compression" and check to see if it is on, if not click "edit" then choose to turn it on. While you are there, look over the several Gzip options that are nearby.

How effective is gzip compression?

Compression of your HTML and CSS files with gzip typically saves around fifty to seventy percent of the file size. This means that it takes less time to load your pages, and less bandwidth is used over all.

How compressed files work on the web

 

 

When a request is made by a browser for a page from your site your webserver returns the smaller compressed file if the browser indicates that it understands the compression. All modern browsers understand and accept compressed files.

Testing compression

To see if gzip compression is working use our gzip compression tool.

Also consider using the page speed tool which will test compression and many other factors.

 

 

 

=================================

=================================

=================================

 

 

 

 

반응형

 

 

 

728x90

 

 

 

 

출처: http://forum.unity3d.com/threads/solved-iis-configuring-it-to-serve-out-the-new-webgl-stack-files-how.284080/

 

 

SOLVED: IIS - configuring it to serve out the new WebGL stack files - how?

 

 

TL,DR;
SOLUTION:

On my host I had to disable Dynamic compression,

In addition it (my browser?) seemed to be finicky about the charset
(.jsgz wanted application/x-javascript; charset=UTF-8)

I also had to register all 5 types in the mime section - not just the two in the original web.config or I got 404.3 errors

For some reason I did not get gzip attached to my RESPONSE HEADERS so I mangled together the following, which attempts to do all these things.

Code (csharp):

 
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
  <rewrite>
  <rules>
  <rule name="Imported Rule 1" enabled="true" stopProcessing="true">
  <match url="(.*)Data(.*)\.js" ignoreCase="true" />
  <conditions logicalGrouping="MatchAll">
  <add input="{HTTP_ACCEPT_ENCODING}" pattern="gzip" ignoreCase="true" />
  </conditions>
  <action type="Rewrite" url="{R:1}Compressed{R:2}.jsgz" />
  </rule>
  <rule name="Imported Rule 2" enabled="true" stopProcessing="true">
  <match url="(.*)Data(.*)\.data" ignoreCase="true" />
  <action type="Rewrite" url="{R:1}Compressed{R:2}.datagz" />
  <conditions>
  </conditions>
  </rule>
  <rule name="Imported Rule 3" enabled="true" stopProcessing="true">
  <match url="(.*)Data(.*)\.mem" ignoreCase="true" />
  <action type="Rewrite" url="{R:1}Compressed{R:2}.memgz" />
  <conditions>
  </conditions>
  </rule>
  <rule name="Imported Rule 4" enabled="true" stopProcessing="true">
  <match url="(.*)Data(.*)\.unity3d" ignoreCase="true" />
  <action type="Rewrite" url="{R:1}Compressed{R:2}.unity3dgz" />
  <conditions>
  </conditions>
  </rule>
  </rules>
        <outboundRules>
  <!-- FIRST SETUP THE SWITCHES FOR THE RESPONSE ENCODING //-->
  <rule name="Rewrite JSGZ header" preCondition="IsJSGZ" stopProcessing="false">
  <match serverVariable="RESPONSE_Content_Encoding" pattern=".*" />
  <action type="Rewrite" value="gzip" />
  </rule>
  <rule name="Rewrite MemGZ header" preCondition="IsMemGZ" stopProcessing="false">
  <match serverVariable="RESPONSE_Content_Encoding" pattern=".*" />
  <action type="Rewrite" value="gzip" />
  </rule>
  <rule name="Rewrite DataGZ header" preCondition="IsDataGZ" stopProcessing="false">
  <match serverVariable="RESPONSE_Content_Encoding" pattern=".*" />
  <action type="Rewrite" value="gzip" />
  </rule>
  <rule name="Rewrite Unity3DGZ header" preCondition="IsUnity3DGZ" stopProcessing="true">
  <match serverVariable="RESPONSE_Content_Encoding" pattern=".*" />
  <action type="Rewrite" value="gzip" />
  </rule>
  <!-- AND SETUP THE MATCHES FOR THE RESPONSE ENCODING SWITCHES //-->
  <preConditions>
  <preCondition name="IsJSGZ">
  <add input="{PATH_INFO}" pattern="\.jsgz$" />
  </preCondition>
  <preCondition name="IsMemGZ">
  <add input="{PATH_INFO}" pattern="\.memgz$" />
  </preCondition>
  <preCondition name="IsDataGZ">
  <add input="{PATH_INFO}" pattern="\.datagz$" />
  </preCondition>
  <preCondition name="IsUnity3DGZ">
  <add input="{PATH_INFO}" pattern="\.unity3dgz$" />
  </preCondition>
  </preConditions>
  </outboundRules>
  </rewrite>
  <staticContent>
  <mimeMap fileExtension=".mem" mimeType="application/octet-stream" />
  <mimeMap fileExtension=".data" mimeType="application/octet-stream" />
  <mimeMap fileExtension=".memgz" mimeType="application/octet-stream" />
  <mimeMap fileExtension=".datagz" mimeType="application/octet-stream" />
  <mimeMap fileExtension=".unity3dgz" mimeType="application/octet-stream" />
  <mimeMap fileExtension=".jsgz" mimeType="application/x-javascript; charset=UTF-8" />
  </staticContent>
  <urlCompression doStaticCompression="true" doDynamicCompression="false" />
</system.webServer>
</configuration>

 

That one web.config needs dropping either in the root of the site you are hosting it on - or the main subfolder of the game you want to serve.

Whether or not you will need some or all of this I do not know.

I needed all of it.

Hope it helps someone. Massive thanks to philwinkel for his tireless efforts of assistance.

 

So what's happening exactly? In your browser's network tab, look at the requests for those files - what kind of response is the web server sending? 

If it's a 404.3 error - mime type missing, then you just need to add the mime types to your application root web.config:

<configuration>
<system.webServer>
<staticContent>
<mimeMap fileExtension=".mp4" mimeType="video/mp4" />
<mimeMap fileExtension=".m4v" mimeType="video/m4v" />
</staticContent>
</system.webServer>
</configuration>

I see you already did that for the .mem and .data mime types, but perhaps you should add all the unique file extensions that a unity webgl will serve?

I'm kind of confused why you are doing rewrites? If the unity webgl build creates static files, you shouldn't have to use any rewrites?

What are you running on IIS, is it ASP. NET web forms, MVC, if so what version of ASP MVC, etc.

Or post a URL and I can take a look. That's just off the top of my head; I haven't used WebGL export yet so I'm not familiar with the different files it exports.

 

twobob



    1. Joined:Jun 28, 2014Messages:1,479
Hi, thanks.

in the hidden under the scrollbar code I did that

Code (csharp):

  1. .... stuff elided
  2.  
  3.      <staticContent>
  4.    <!-- AND MIME REGISTER THE TYPES //-->
  5.          <mimeMap fileExtension=".jsgz" mimeType="application/x-javascript" />
  6.        <mimeMap fileExtension=".datagz" mimeType="application/octet-stream" />
  7.        <mimeMap fileExtension=".memgz" mimeType="application/octet-stream" />
  8.        <mimeMap fileExtension=".unity3dgz" mimeType="application/octet-stream" />
  9.        <mimeMap fileExtension=".mem" mimeType="application/octet-stream" />
  10.        <mimeMap fileExtension=".data" mimeType="application/octet-stream" />
  11.      </staticContent>
  12. </system.webServer>
  13. </configuration>
  14.  
that was my thought also.

I do the rewrites as that is the unity way of doing things. as outlined in the top post in the section starting

"and the .htaccess file (which is not IIS friendly directly but can be imported) says:"

Thanks very much for answering though!!! I really appreciate any input.


RE THE SERVER: Vanilla 2008 Datacenter edition. so.. .Net web forms I guess.
I have full access to the servers configs.
np, in a nutshell I think you just add mime types and configure compression in webconfig. I don't think any rewrites should be necessary. I'm not familiar with the htaccess importer, I'd probably just configure it manually and skip the htaccess.

As for compression in IIS7, this post may be helpful:
http://weblog.west-wind.com/posts/2011/May/05/Builtin-GZipDeflate-Compression-on-IIS-7x
(just skimmed it, seemed about right)

 

twobob



    1. Joined:Jun 28, 2014Messages:1,479
Yup, read that one.
Tried it. Compression is on and working fine.

Here is a quick precis

this is what I did:

1) Upload to server (I was not clear if I had to actually upload the two huge .mem and .data file in /DATA, from my reading of the rewrite rules below, "No, I do not have to" since all requests for those files will be redirected to their pre-compressed cousins. (but I did anyways to be sure)

2) checked that the web.config was being honoured to serve out the .mem and .data stuff (I also actually tried hard-coding the MIME TYPES just for sanities sake, yup, web.config or hard coded is same) EDIT <--- ACTUALLY In the end I had to hard code them.

3) Imported the rules into URL rewrite via the IMPORT RULES button and double checked they were sensible. They all seemed fine - 4 rules - redirecting unzipped requests to zipped equivalents. (they need little fix though as outlined in top post)

4) Checked that the server has dynamic and static compression installed and enabled for the domain (which it does)

5) revisited the .htaccess to see what I had missed.

It's the final bit where in the .htaccess it would have been handled by:

AddEncoding gzip .jsgz AddEncoding gzip .datagz AddEncoding gzip .memgz AddEncoding gzip .unity3dgz

I /think/ it is this bit maybe where it goes wrong. Not sure how to do this is IIS?

I will upload a tiny test project so people can see the errors. http://kaycare.co.uk/games/WebGL/

 


    1. twobob, Dec 5, 2014
    2. #5
    3. Last edited: Dec 5, 2014
    4.  

twobob



    1. Joined:Jun 28, 2014Messages:1,479
well fixed all the errors I could find and ended up with 
"NetworkError: 404 Not Found - http://kaycare.co.uk/games/WebGL/Data/UnityProgress.js"
again. Sigh...

Will keep digging.

 

philwinkel



    1. Joined:Jun 6, 2013Messages:271
it looks like something must be messed up in the web.config. all static files are throwing 500's. you may want to turn on customErrors so you can see the IIS error. 

<customErrors mode="RemoteOnly"/>

"RemoteOnly" will allow you to remote into the server and check the response, if it's a staging environment where you don't care, you can set it to "On"

    1.  

 


 

Yup. Many thanks - I have fixed particular error now. It was a stray character in the xml. Doh

However the real issue appears to be:

HTTP Error 404.3 - Not Found
The page you are requesting cannot be served because of the extension configuration. If the page is a script, add a handler. If the file should be downloaded, add a MIME map.

which I clearly have done.

I will go hard code them in the IIS config instead and rip the web.config again. sigh.

Thanks for looking. Driving me potato cakes

 

twobob

    1. Joined:Jun 28, 2014Messages:1,479
    2.  
Okay so, Finally, I have the files serving.

The STATIC section of the web.config was not being honored. Putting the MIME types into IIS finally allowed the files throughBUT now they appear to not be being unencoded at my side.

Sigh.

application/x-javascript was the type I put on the .jsgz files.... is that wrong?

UnityProgress.js:1 Uncaught SyntaxError: Unexpected token ILLEGAL
UnityConfig.js:1 Uncaught SyntaxError: Unexpected token ILLEGAL
fileloader.js:1 Uncaught SyntaxError: Unexpected token ILLEGAL
WebGL.js:1 Uncaught SyntaxError: Unexpected token ILLEGAL

Pretty sure that means I am being served the zipped js file now. and it isnt being parsed?

    1.  

 

 
The responses all look okay server side?

and by accessing kaycare.co.uk/games/WebGL/data/fileloader.js you can now see a zipped version appearing...

 

philwinkel

    1. Joined:Jun 6, 2013Messages:271
    2.  
I just did a test WebGL build in ASP MVC 4 website:

Due to the directory structure of MVC I changed some relative paths for "Data/" to "/Data/" in the index.html file that the webgl build spits out.

As expected 403.4 errors on the MIME types that I have not configured in my web.config yet,
    1.  

 



Added the MIME maps to the web config:
<staticContent>
<mimeMap fileExtension=".data" mimeType="application/octet-stream" />
<mimeMap fileExtension=".mem" mimeType="application/octet-stream" />
</staticContent>

That was enough to get the build running (albeit without compression)
http://i.imgur.com/tjwUEWg.png

For compression.. I'll try deploying to my shared web host, as I don't want to change IIS express configuration right now. I'm just using standard web.config compression, relevant web.config is as follows:

Code (CSharp):

  1.   <system.webServer>
  2.  
  3. ..
  4.  
  5.     <staticContent>
  6.       <mimeMap fileExtension=".data" mimeType="application/octet-stream" />
  7.       <mimeMap fileExtension=".mem" mimeType="application/octet-stream" />
  8.     </staticContent>
  9.     <httpCompression directory="%SystemDrive%\inetpub\temp\IIS Temporary Compressed Files">
  10.       <scheme name="gzip" dll="%Windir%\system32\inetsrv\gzip.dll"/>
  11.       <dynamicTypes>
  12.         <add mimeType="text/*" enabled="true"/>
  13.         <add mimeType="message/*" enabled="true"/>
  14.         <add mimeType="application/javascript" enabled="true"/>
  15.         <add mimeType="*/*" enabled="true"/>
  16.       </dynamicTypes>
  17.       <staticTypes>
  18.         <add mimeType="text/*" enabled="true"/>
  19.         <add mimeType="message/*" enabled="true"/>
  20.         <add mimeType="application/javascript" enabled="true"/>
  21.         <add mimeType="*/*" enabled="true"/>
  22.       </staticTypes>
  23.     </httpCompression>
  24.     <urlCompression doStaticCompression="true" doDynamicCompression="true" />
  25.   </system.webServer>
I pretty much picked that up off some website somewhere. I think this part should enable compression on everything..
<add mimeType="*/*" enabled="true"/>

and it appears to be gzipping and serving all the files,
    1.  

 



I'm not using any rewrites, I think that was specific to wahtever configuration the unity people were using. Although, I think my configuration is not using the files from the "compressed" directory. Those must be pre-gzipped or something. I've never done that, I've always had my web server do the gzipping and have the server cache the response. I'll have to see about that next..

 

twobob

    1. Joined:Jun 28, 2014Messages:1,479
    2.  
The rewrites are to enable the huge versions of the files to be replaced "pre-realtime" with the pre-zipped versions of the files. Since zipping 124mb everytime someone wanted to play your game would soon kill your server.

(they should be in the compressed folder)

Well, it sounds like I am right at the very verge of getting this thing working.

Although I am back at exactly the same point I was when I started this thread.

.jsgz files being served. Nothing else happening once they are returned. I must have them encoded wrong or something stupid. will keep digging then. thanks for your tips.

    1.  

 




RE POST: Aye I remember that post from years ago, probably when I first did gzip stuff in my own apps.
I have actually written custom http handlers in the past, - that used gzip - unbelievably, looking at the total lack of understanding going on today.

Brain getting old. Will give this yet another go.

 

philwinkel

    1. Joined:Jun 6, 2013Messages:271
    2.  
i'll try to get it working with the compressed files, are you using ASP MVC?

 

twobob

    1. Joined:Jun 28, 2014Messages:1,479
    2.  
Vanilla 2008 server. IIS 7.5, whatever came on that.

Model View Controller? Errrr.... Honestly I don't know. Pretty sure that post dates the servers birthdate.

I only use this box to shove out files and the occasional, very lightweight, Asp .Net programming job.
It's just a file workhorse. Hence me being pretty unsure about its potential guts.

EDIT: Hmm I seem to recall that stuff came out about a year after the server did. so I doubt it.

 

philwinkel

    1. Joined:Jun 6, 2013Messages:271
    2.  
I think the rewrites are not adding the correct HTTP header to the response, that should tell the browser it's using compression. It should be something like "content-encoding: gzip" or whatever.

It seems like the browser doesn't realize that the response is gzipped, and it's getting all this crazy garbled gzipped javascript data that it can't understand. Therefore the "unexpected token" errors

    1.  

 



there's no content-encoding header in the response, so the browser just tries to read it without decompressing and it looks like this:

    1.  

 


 

twobob

    1. Joined:Jun 28, 2014Messages:1,479
    2.  
Yup, my thoughts too.

Except it says here that I am sending that header back

    1.  

 



Quite the mystery.

So I elided the bit of web.config trickery I posted in the top post, so as to NOT pass back the gzip header. Same thing. Not processed. gah 


I also tried the application/javascript type just in case.

 

philwinkel

    1. Joined:Jun 6, 2013Messages:271
    2.  
it still doesn't seem to be passing Content-Encoding header back to chrome at least. It's weird that it's working in firefox.. When you look at the response, does it look like javascript?

 

twobob

    1. Joined:Jun 28, 2014Messages:1,479
    2.  
nope, still junk. compressed junk.

Code (csharp):

  1.  
  2.     <rewrite>
  3.          <outboundRules>
  4.              <rule name="Rewrite JSGZ header" preCondition="IsJSGZ" stopProcessing="false">
  5.                  <match serverVariable="RESPONSE_Content_Encoding" pattern=".*" />
  6.                  <action type="Rewrite" value="gzip" />
  7.              </rule>
  8.             <rule name="Rewrite MemGZ header" preCondition="IsMemGZ" stopProcessing="false">
  9.                  <match serverVariable="RESPONSE_Content_Encoding" pattern=".*" />
  10.                  <action type="Rewrite" value="gzip" />
  11.              </rule>
  12.               <rule name="Rewrite DataGZ header" preCondition="IsDataGZ" stopProcessing="false">
  13.                  <match serverVariable="RESPONSE_Content_Encoding" pattern=".*" />
  14.                  <action type="Rewrite" value="gzip" />
  15.              </rule>
  16.             <rule name="Rewrite Unity3DGZ header" preCondition="IsUnity3DGZ" stopProcessing="false">
  17.                  <match serverVariable="RESPONSE_Content_Encoding" pattern=".*" />
  18.                  <action type="Rewrite" value="gzip" />
  19.              </rule>
  20.             <preConditions>
  21.                  <preCondition name="IsJSGZ">
  22.                      <add input="{PATH_INFO}" pattern="\.jsgz$" />
  23.             </preCondition>
  24.                  <preCondition name="IsMemGZ">
  25.                      <add input="{PATH_INFO}" pattern="\.memgz$" />
  26.                  </preCondition>
  27.             <preCondition name="IsDataGZ">
  28.                      <add input="{PATH_INFO}" pattern="\.datagz$" />
  29.                  </preCondition>
  30.             <preCondition name="IsUnity3DGZ">
  31.                      <add input="{PATH_INFO}" pattern="\.unity3dgz$" />
  32.              </preCondition>
  33.              </preConditions>
  34.         </outboundRules>
  35.      </rewrite>
  36.  
without those it does not send those gzip headers, period. so either that is somehow affecting the wrong output and I need to put it somewhere else.... Like in the main IIS config? I have zero idea how to do that though.

 

twobob

Joined:Jun 28, 2014Messages:1,479

 

did you get yours going? the compressed one?

http://stackoverflow.com/questions/...type-header-to-use-when-serving-gzipped-files

Seems like this is similar, but only cos he has put the wrong type in....

Maybe the type is not being parsed. bah. I dunno.


Chrome seems to be getting the headers now as far as I can see, neither it, nor firefox, honor the flag.

    1.  

 


 

philwinkel

    1. Joined:Jun 6, 2013Messages:271
    2.  
Well since those files are precompressed, maybe you should disable httpCompression on them in web config. It's possible they are getting double compressed. 

In which case the browser would decompress and itd still look like garbage.

 

twobob

    1. Joined:Jun 28, 2014Messages:1,479
    2.  
ooh
Good call. will try that..

Sigh. Sadly not.

Code (csharp):

  1.  
  2. <configuration>
  3. <system.webServer>
  4.         <urlCompression doStaticCompression="false" doDynamicCompression="false"/>
  5. ...
  6.  
tried in all relevant locations, cache cleared between each or disabled as appropriate. Chrome/ff

Really good thought though.

philwinkel

    1. Joined:Jun 6, 2013Messages:271
    2.  
Hm, just to make sure I'd try deleting web config, hit the site and make sure you get an error, then push web config again.. Or just restart site in IIS or something. I've had a few times where it was hanging onto certain web config settings.

Probably not the problem, but just to make sure. 

I'll have to take a look again in a few mins when I'm back at a computer, that is a mystery for sure...

 

twobob

    1. Joined:Jun 28, 2014Messages:1,479
    2.  
sure thing.

I'll go raze it to the ground and reboot the domain.

 

twobob

    1. Joined:Jun 28, 2014Messages:1,479
    2.  
did that. removed web.config, 404.3, added custom web.config with the gzip header handling included. 404.3 (that IS a mystery, checked it wasn't xml order related etc.), 

so reverted back to hard coded IIS management MIME types, that gets us past the 404.3 and onto the files being served but the response encoding being utterly ignored.

Tried mangling the return content types, just broke stuff as expected, with pretty warnings.

Did everything I could think of. went through all the configurations again. rebooted domain.

In precis: Attempting to indicate .jsgz MIME type in the web.config after the URL rewrite fails on a 404.3 (as you saw), that is puzzling.

Placing .jsgz in the default mime types and using the rewrite thing for the content headers looks like it works on paper but nothing happens on the client side for the unzipping.

Totally befuddled.

There HAS TO BE SOMEONE who has done this.
Jeepers, it's so basic.

 

twobob

    1. Joined:Jun 28, 2014Messages:1,479
    2.  
Well. I have even ripped the web.config completely now.

and weirdly the server IS NOW appending the gzip to the response even without massage.

an it STILL doesn't blumming work. So basically I have put on the files, added the MIME types to the main domain information, checked the responses are valid with the right headers.

And it don't work. gah. out of ideas

 

philwinkel

Joined:Jun 6, 2013Messages:271

 

I read some people apparently have issues w/ stuff that uses "too high" of gzip compression,http://stackoverflow.com/questions/...-i-get-illegal-character-token-errors-in-both (bottom comment)

The unity gzipped files looked like they were super-compressed; maybe it's running into errors because of the high compression or something. Or maybe unity's spitting out invalid compressed files. Who knows, it's a beta.

Is this for a production game where you need super optimized compression? Can always skip the precompressed files, disable the rewrites, re-enable the httpCompression and use IIS built in gzipping, make sure it's using static compression so it can be cached in the browser. Admittedly it wasn't as compressed as those precompressed files, maybe like 25mb instead of 15mb or whatever. On the fly compression may kind of tax the web server, I'm not sure if/how IIS caches those gzipped responses. I would hope if the web server is gzipping a static file, it caches it somewhere. I'm not sure.

Precompressed would obviously be the best, but it's a beta (who knows), and it's friday, I kinda give up for now xD

If you continue down the precompressed route, I'd try skipping unity's precompressed files and compressing them on your own. Just to rule that out. Or verify w/ someone that those precompressed files are working.

 

twobob

    1. Joined:Jun 28, 2014Messages:1,479
    2.  
Yeah me too. Thanks dude. I too read that post about the super compression, In fact I think I've read like every relevant post on the first 30 pages of goggle results for several search terms.

Fact is without the compression the files are ENORMOUS. VAST. that one project has just a CUBE and a PLANE in it.

it comes in a nearly a quarter of a gig mate. hardly serviceable.
    1.  

 

 

I've raised a request with my hosts, maybe they will take pity on me.

EDIT: They did not.


and I have tried every type of build. lowest to highest. and its not compression its optimisation they do.
I watched the hour long video about it earlier.

:\

Have a great w/e!! 




.

 

Caio_Lib

    1. Joined:Mar 4, 2014Messages:63
    2.  
Hi, I'm using IIS server.
I built a test game to see if I can help, it's just a cube and works ( worked using both optimization 'slow' and 'fastest', fastest is used now ):
http://www.liberalistudios.com/trabalhos/webgl/example/

My web.config:

Code (CSharp):

  1. <?xml version="1.0" encoding="utf-8"?>
  2. <configuration>
  3.     <system.webServer>
  4.         <staticContent>
  5.             <remove fileExtension=".mem" />
  6.             <mimeMap fileExtension=".mem" mimeType="application/octet-stream" />
  7.             <remove fileExtension=".data" />
  8.             <mimeMap fileExtension=".data" mimeType="application/octet-stream" />      
  9.         </staticContent>
  10.     </system.webServer>
  11. </configuration>
Is based on TDMIsh answer: http://forum.unity3d.com/threads/how-to-properly-host-webgl-content.282364/
Even deleting .htaccess file it's working.

I thought you were using MVC or friendly url but your site seems to be using just html. ( http://kaycare.co.uk/index.html )
What I would suggest to you is:
- If you're not using ASP NET to backup and replace your web.config with the one above.
- Test a build using just a cube
- If using just a cube and web.config works but your game doesn't I think it is the compression problem that you're saying!

Hope it helps, or at least give you some light!

 

philwinkel

    1. Joined:Jun 6, 2013Messages:271
    2.  

twobob said: 

Fact is without the compression the files are ENORMOUS. VAST. that one project has just a CUBE and a PLANE in it.

Right - I mean as a temporary workaround for the issue with the precompressed files, you could skip using them and have IIS gzip the raw ones. The total size of downloading this empty build with IIS gzipping it was 31.9MB. IIS was still able to gzip it pretty well. Not as good as pre-compressed, but still fairly compressed.

(in chrome "size" is the size downloaded, "content" is the actual uncompressed size of the file - so IIS gzip compressed build.js from 108mb down to 26.5mb)

I did the webgl build on my computer at work, so I forget how big the precompressed files were, I think they were only slightly smaller.

    1.  

 


 

twobob

    1. Joined:Jun 28, 2014Messages:1,479
    2.  
Thanks for the thoughts people. 

My hosts were ultimately unhelpful. so I kept digging.

I managed to find this in the new firefox developer toolbar. 
"The character encoding of the plain text document was not declared. The document will render with garbled text in some browser configurations if the document contains characters from outside the US-ASCII range. The character encoding of the file needs to be declared in the transfer protocol or file needs to use a byte order mark as an encoding signature."

So I am looking into that next, tried disabling Dynamic and Static compression manually via IIS on the site too, so it's not that. :\ another day, another segfault

 

twobob

Joined:Jun 28, 2014Messages:1,479

 

So... A combination of

Code (csharp):

  1.  
  2. <?xml version="1.0" encoding="UTF-8"?>
  3. <configuration>
  4. <system.webServer>
  5.      <rewrite>
  6.          <outboundRules>
  7.         <!-- FIRST SETUP THE SWITCHES FOR THE RESPONSE ENCODING //-->
  8.              <rule name="Rewrite JSGZ header" preCondition="IsJSGZ" stopProcessing="false">
  9.                  <match serverVariable="RESPONSE_Content_Encoding" pattern=".*" />
  10.                  <action type="Rewrite" value="gzip" />
  11.              </rule>
  12.             <rule name="Rewrite MemGZ header" preCondition="IsMemGZ" stopProcessing="false">
  13.                  <match serverVariable="RESPONSE_Content_Encoding" pattern=".*" />
  14.                  <action type="Rewrite" value="gzip" />
  15.              </rule>
  16.               <rule name="Rewrite DataGZ header" preCondition="IsDataGZ" stopProcessing="false">
  17.                  <match serverVariable="RESPONSE_Content_Encoding" pattern=".*" />
  18.                  <action type="Rewrite" value="gzip" />
  19.              </rule>
  20.             <rule name="Rewrite Unity3DGZ header" preCondition="IsUnity3DGZ" stopProcessing="true">
  21.                  <match serverVariable="RESPONSE_Content_Encoding" pattern=".*" />
  22.                  <action type="Rewrite" value="gzip" />
  23.              </rule>
  24.              <!-- AND SETUP THE MATCHES FOR THE RESPONSE ENCODING SWITCHES //-->
  25.             <preConditions>
  26.                  <preCondition name="IsJSGZ">
  27.                      <add input="{PATH_INFO}" pattern="\.jsgz$" />
  28.             </preCondition>
  29.                  <preCondition name="IsMemGZ">
  30.                      <add input="{PATH_INFO}" pattern="\.memgz$" />
  31.                  </preCondition>
  32.             <preCondition name="IsDataGZ">
  33.                      <add input="{PATH_INFO}" pattern="\.datagz$" />
  34.                  </preCondition>
  35.             <preCondition name="IsUnity3DGZ">
  36.                      <add input="{PATH_INFO}" pattern="\.unity3dgz$" />
  37.                  </preCondition>
  38.              </preConditions>
  39.         </outboundRules>
  40.      </rewrite>
  41. </system.webServer>
  42. </configuration>
  43.  
plus, DISABLING dynamic compression (manually, not in the config)

and manually adding the (entire list of 5) types to the MIME register

and adding
application/x-javascript; charset=UTF-8 
to the MIME information of jsgz.

appears to have done the job!!!!!!
WOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOTage.!!!!!!
Still checking but heck I can see real script content where there was only compressed noise before. That has to work... testing now.

EDIT: Yup files being served. I'll see if I can get it to work without the hardcoding....

philwinkel

    1. Joined:Jun 6, 2013Messages:271
    2.  
Nice, glad you got that figured out! What an ordeal...

Next week I think I'm gonna attack it from a different angle. I like to try and configure things in web.config and code as opposed to IIS stuff.. I'm gonna try to route the requests for the unity JS / MEM / DATA files to an MVC action... which would contain code that does the same thing that those URL rewrites are doing (check if the request headers indicate the browser supports compression, and serve out the correct precompressed file).

I believe you can route requests for specific directory/file paths to ASP MVC actions instead of having IIS serve them out as static files, by configuring system.webServer handlers in the web.config, and then set up some MVC routes that catch the requests for those files.

(I think it's also probably possible to do with a regular ASP .NET webforms project, but I'm not a big fan.. gotta have my MVC)

My goal is basically to get it set up so you can just drop the unity WebGL build into the root of the website and have it work, without having to change stuff in IIS.


Once again tho, nice work! I'm sure people trying to host on a windows server will find this helpful.

 

philwinkel



    1. Joined:Jun 6, 2013Messages:271
Just tried the alternate solution I mentioned in the above post, and it seems to work. I haven't thought through all the possible implications of doing this instead of the IIS rewrite. 

Example project download (VS2013 community, ASP MVC 5, .NET 4.5):
https://mega.co.nz/#!0tYRGbDL!oH2iLb-6H2KX1UnMHyNhC3ualfp_tFnoqNvg81FN0fE

Workflow is basically: do your WebGL build, then copy it into the root of this ASP MVC website. As long as IIS is configured correctly to host the website (integrated pipeline, .NET 4.5), it should work without any IIS configuration changes or rewrite rules.

Some details of the implementation:

1. Disable IIS serving out the static JS, MEM, and DATA files, but only for the /Data/ directory. Add system.webServer handlers to web.config:

Code (CSharp):

  1.   <system.webServer>
  2. ...
  3.     <handlers>
  4.       <!-- create handlers so requests to the Unity WebGL static files get routed through ASP MVC -->
  5.       <add name="UnityJSHandler" path="Data/*.js" verb="GET" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" />
  6.       <add name="UnityMemHandler" path="Data/*.mem" verb="GET" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" />
  7.       <add name="UnityDataHandler" path="Data/*.data" verb="GET" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" />
  8.     </handlers>
With those handlers in place, IIS won't serve out the static files in the Data/ directory.

2. Next, configure MVC routing in RouteConfig.cs. Catch the requests for static files in the Data directory, and send them to the UnityStaticFile controller's Index action, with the requested file name as a parameter.

Code (CSharp):

  1.     public class RouteConfig
  2.     {
  3.         public static void RegisterRoutes(RouteCollection routes)
  4.         {
  5.             routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
  6.  
  7.             // unity static file route handler. routes requests to /data/ js mem data files to UnityStaticFile controller's Index action
  8.             routes.RouteExistingFiles = true;
  9.  
  10.             routes.MapRoute(
  11.                 "UnityStaticFiles",
  12.                 "Data/{*file}",
  13.                 new {Controller = "UnityStaticFile"action = "Index"});
  14.  
  15.             routes.MapRoute(
  16.                 name: "Default",
  17.                 url: "{controller}/{action}/{id}",
  18.                 defaults: new { controller = "Home"action = "Index", id = UrlParameter.Optional }
  19.             );
  20.         }
  21.     }

3. Configure UnityStaticFile controller to serve the correct files depending on the Request's accept-encoding header:

Code (CSharp):

  1.     public class UnityStaticFileController : Controller
  2.     {
  3.         [OutputCache(Duration = 1200, VaryByHeader = "Accept-Encoding")]
  4.         public ActionResult Index(string file)
  5.         {
  6.             var acceptEncoding = Request.Headers.AllKeys.FirstOrDefault(key => key.ToLower() == "accept-encoding");
  7.  
  8.             // if no accept encoding header, return raw file (eww)
  9.             if (acceptEncoding == null)
  10.                 return new FilePathResult("/Data/" + file, getContentType(file));
  11.  
  12.             // if accept encoding gzip, return compressed files
  13.             if (Request.Headers[acceptEncoding].Contains("gzip"))
  14.             {
  15.                 Response.Headers.Add("Content-Encoding""gzip");
  16.                 return new FilePathResult("/Compressed/" + file + "gz", getContentType(file));
  17.             }
  18.  
  19.             // bad request
  20.             return new HttpStatusCodeResult(HttpStatusCode.InternalServerError);
  21.         }
  22.  
  23.         private string getContentType(string file)
  24.         {
  25.             var ext = Path.GetExtension(file);
  26.             if (ext.Contains("js"))
  27.                 return "text/javascript; charset=UTF-8";
  28.  
  29.             // else
  30.             return "application/x-octet-stream";
  31.         }
  32.     }
Code is kind of hacked together, but it basically does the same thing that those IIS rewrites are doing - if there is no "accept-encoding" header, it just serves the non-gzipped files. If there is an "accept-encoding: gzip" header, it sets the "Response Content-Encoding: gzip" header, and returns the compressed file. I'm using an [OutputCache] attribute to enable caching, with the VaryByHeader set to Accept-Encoding, so it should serve a cached response correctly depending on the Accept-Encoding header. (disclaimer: I have not fully tested, but the code path returning the compressed files worked for me in chrome)

4. I set up the Home controller's Index action (it handles requests to the website root) to just serve the index.html file. So it's not using an ASP MVC view. This just basically serves the index.html file (in an ASP MVC way..) when you hit the root of the website.

5. Side note, if running localhost in Visual Studio you may need to disable Browser Link, or it'll throw Out of Memory exceptions on huge static javascript files:
    1.  

 



Seems to be working:

    1.  

 


 

 

 

=================================

=================================

=================================

 

 

반응형


관련글 더보기

댓글 영역