Please refer - http://web.guru99.com/perl-subroutines/ I am calling the file http://code.guru99.com/perl/perl.js inside the corresponding wordpress post.
The file is 750KB in size I am using WP Super cache but it does not cache or compress this file (maybe since it’s called in the post section).
How can I compress and cache this file before serving to the end user ?

Recommended Answers

All 5 Replies

if an apache server you can enable mod_gzip or mod_deflate in .htaccess for this filetype something like the codescrap below, which zips the most zippable filetypes

<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>

cache can be set in .htaaccess as well using mod_expires, the instructional search is left to the user, because I dont have the code stuck in my head for that

edit: reread the post,
and
it is considered improper to serve a file located on someone else's server as part of your system unless the other person explicity agrees and offers that service. eg google script, because that third party has to pay the banmdwidth costs, it is considered theft. likewise pinching the code itself is considered theft of intellectual property
the code above only works if the file is hosted on your site
if the author permits, place it on your host, and serve it from there with the appropriate attribution,

Also once you download the file to your server, you can just run it through man of the javascript minifiers out there. There are tons online. The most popular library to use right now is UglifyJS it will also shrink your variables which gives you a little obfuscation. I personally just use the online tools that are out there. I usually use Click Here. But I totally agree you should not be using it from someone elses server as you are stealing bandwidth, it is the same thing if someone found your site, then linked pictures from your site to theirs. You would then be serving all of their bandwidth for the images he is serving.

I think mod_deflate / mod_gzip is a better suggestion
this line mod_gzip_item_include file .(html?|txt|css|js|php|pl)$
compresses all the filetypes listed, served from the server

http://code.guru99.com/perl/perl.js is my site :)
I think I have found the issue! No need to htaccess changes
The problem is files are being appended with “?fe74d6”
for example http://web.guru99.com/wp-content/uploads/dynamic_avia/enfold.css?fe74d6
I am not sure where and how this “?fe74d6” comes from!
I am using wordpress for my site and have W3Total cache installed , which is able to gzip the files without “?fe74d6”
Can you guys help ?

I apologise for jumping to conclusions
it happens too often, and I just expected it.

I clicked view source, the parameter has to be added somewhere, perhaps in the wordpress plugins being used, just about everything in the page <head> has had the parameter added if it isnt in the source, something has to be doing it in the serverside scripts

<script type="text/javascript" src="http://web.guru99.com/wp-includes/js/perl.js?fe74d6"></script>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js?fe74d6">></script>
<script src="http://web.guru99.com/wp-includes/js/code.js?fe74d6"></script>
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.