I am having a problem with gzip compression on my site. I've combined several javascript files to one files and they work ok without compression. Afterwards I've compressed them (gzip) and tried to run the site again, but get the following error:
Uncaught SyntaxError: Unexpected token ILLEGAL
I've compressed the file using several methods, one using gzip software and I also tried other gzip online compression tools like this one.
I can't understand why I get this error why it doesn't work, because the non-compressed version does work. I ran the site on Chrome, latest version.
It also tells me that the error is in line 1
all_js.js.gz:1
Of course the compressed code has many lines, not just one.
I've read a few answers, but nothing regarding gzip compression.
I get this error when working with Visual Studio (ASP.NET) on local machine.
I tried serving the file from S3 with 'application/x-gzip' headers, but it still didn't work. I want to serve my files via CDN after compressing, so I don't search for server compression solutions.
You cannot compress a javascript file with gzip or any other zip routine and load it into your webpage.
You can do one of two things:
Use a javascript code compression tool like the YUI compressor.
Configure your webserver to compress the files (please read the documentation of your webserver, it should not be very difficult)
Related
My question is strictly related to the deployment. My code is good. At first I asked this question, please read that question as well. I have given detailed info about the project there also. However, I got some good response and I followed these steps from the same:
You have to use ng build --prod for compile your development file.
Then you need to setup your node.js file.
Then just upload all the server files and dist folder to server.
And run the server using pm2 .
And run just pm2 start server.js
Everything looks good. pm2 is also doing its job.
But my web page is absolutely blank with three errors on the console.. Only the project title is there on the browser tab.
Those three errors are:
Loading module from “http://localhost:3000/runtime-es2015.858f8dd898b75fe86926.js” was blocked because of a disallowed MIME type (“text/html”).
Loading module from “http://localhost:3000/polyfills-es2015.5728f680576ca47e99fe.js” was blocked because of a disallowed MIME type (“text/html”).
Loading module from “http://localhost:3000/main-es2015.3f40e4ee14a8137ebfaa.js” was blocked because of a disallowed MIME type (“text/html”).
I have tried this on both chrome and firefox. Please tell me where I failed.
I'm new to all things coding and have tried to use Azure to host a web app. The app is JavaScript using PHP to process MYSQL data. Everything works locally as expected. But when I try to access the app where it's hosted, I see 404 (Not Found) errors on all of my calls to .php files.
I'm using jQuery's getJSON to get data:
$.getJSON('bin/myFile.php', function(data) {
// Process data
})
Then in the browser console I see:
GET https://mysite.azurewebsites.net/bin/myFile.php 404 (Not Found)
But, if I move that file to the root directory and drop the bin/ from my call, it works perfectly. All other calls to files in folders work fine (images, scripts, styles), only the php files in the bin folder return this error.
Anyone know why?
Answer from comments:
Try renaming your bin folder. That is normally where binary files are placed in a windows web app environment, so it's possible the Azure server is configured to not serve any files from that location –
Rory McCrossan
Sep 26 '17 at 16:22
My application has several javascript imports which work without issue, one does not. All js files were served as "text/html"
<script src="app/node_modules/lodash/index.js" type="application/javascript"></script>
The file works fine locally (VS2010) but not when deployed to the IIS server. It fails in both IE11 and Chrome with a 500 error.
Microsoft VBScript compilation error '800a0400'
Expected statement
app/node_modules/lodash/index.js, line 88
-([\s\S]+?)
^
I have seen similar issues with UnderscoreJs as well.
The following fixes removed the MIME bypasses and allowed them to be set correctly.
In IIS6: Remove application extension for .js
IIS7: Remove handler mapping for .js
I just got the GZip software from this site http://www.gzip.org/#intro and was looking at it and tried to convert a javascript file which it just converted directly and changed the extension to gz.Can someone tell me how can we create a new file without modifying the original file using GZip command line and also is this GZip file the same which say a web server like IIS creates and sends to the client when compression is enabled.
I am thinking of GZipping all our JS and CSS and HTMl files before hand so the web server can directly render it .I know the web server by itself only renders these zip fles if the client supports but I m just trying some new stuff.
Assuming you're on a *NIX machine, you can use
gzip -c FILE > FILE.gz
to write the gzipped data to a different file. The -c writes to stdout, and the > redirects stdout to a file. If you have many you could try a loop in Bash:
for file in *.js
do
gzip -c "$file" > "${file}.gz"
done
Also, be really really certain your server falls back on the nongzipped versions if the client doesn't support it!
179KB of jQuery is Minified and Gzipped to 26KB. I am trying to do the same compressions to my javascript files and found the Yuicompressor to Minify it. But I am still searching for a way to Gzip it.
How can I Gzip my Javascript files?
If you are using it in a webpage, gzip is a configuration method in your web server. The file is gzipped by the server, sent to the browser. No manual action is needed. For Apache: http://httpd.apache.org/docs/2.0/mod/mod_deflate.html.
If you are delivering the code to developers, you could use the gzip command.
You would use gzip, the GNU compression utility. Luckily, the gzip algorithm and file structure is implemented by numerous other tools, such as 7zip (for Windows). You can configure your server (via mod_deflate or others) to compress files on the fly, but for static content its a waste of CPU power.
Here is an article which shows how to transparently serve pre-compressed gzip to browsers which support it: http://blog.alien109.com/2009/03/17/gzip-your-javascript/
You could also use zbugs.com - just provide your website url and it will do everything for you.