AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |
Back to Blog
Php minify js files3/16/2024 Aside: Template TagsĪ quick preview of how HiFi handles stylesheets and scripts to give you a bit of context: We added two new tags to our templating language. Nginx has a HttpRewriteModule, which is similar to Apache's mod_rewrite, so I figured there must be a way to replicate the Minify sample code in the new environment. For HiFi, we decided on Nginx, as the configuration for running many sites off of the same code-base is much simpler. This was almost what we were looking for, except for two things: it requires a very specific url structure-with all JS and CSS files stored inside the Minify folder-and we are not using Apache. There is some sample code included in the Minify download that uses Apache url rewriting to take a more "normal"-looking url and point it to the Minified version. Ideally, after a file is cached the first time nginx would serve the compressed file directly. However with this setup, even after caching the minified files server-side, the PHP interpreter is involved in delivering the file, which is relatively inefficient. The normal way to use Minify is to install it in your root directory and call its main file with a query string to specify the specific files that should be included: /min/?f=js/jquery.js,js/,js/setup.js. Both CSS and Javascript minification libraries are included and they can easily be switched out if you prefer another library. There is a very useful and stable Minify project on Google Code. Here I am going to discuss the technical details of how we set things up on our n ginx server. You can read more details about the benefits and our template-side implementation in a previous post. On complex sites, this minification can have a significant impact on page load times. Aggregating them into a single one per content type can be a significant optimization advantage.For our HiFi content management system we wanted to automatically combine and compress CSS and Javascript files. However, it is well worth the benefit if you have several independent asset requests. Using Grunt does add a certain level of complexity that some front-enders might have difficulty understanding. However, I would recommend using Grunt since that will likely translate better to more projects and internal ecosystems. A web search will yield an enormous list of JavaScript and StyleSheet minifiers, compressors. Essentially, what PageSpeed is partially telling you to do is combine (aka bundle) all those render blocking, individual. Task runners are kinda phasing out the need to manage assets server side in many ways though given the right use case there is an argument to use Assetic or possibly both. Minify CSS Minifying CSS files can reduce network payload sizes. However, with the invention of nodejs based task runners like grunt Assetic isn’t nearly as *modern of an approach anymore. If that puts you off you could also try using Assetic. Grunt is a JavaScript based task runner that could be considered the *current industry standard for aggregating css and javascript files not to mention a whole host of other things. Having said that I suggest you look into using Grunt. This doesn’t really have anything to do with MVC. Is this suppose to happen with MVC logic? It doesn’t do any jquery events while on the hard-coded PHP one, it works just fine. I’m using jquery-1.9.1.min.js for most of my javascript events on both the hard-coded PHP and the MVC one, but for the MVC one. The main problem for this is that for some reason, I have to move around the original javascript on the MVC one because it won’t work properly. Example of this would be thisisjustacssfile.css will have the content tpe header “text/css”. If the fake file name exists, it will require the original and it’ll set the appropriate content-type. If it ends with either one of them, it will then go into the appropriate table in the database and search for the fake file name. In the MVC one, I’ve masked the original file names with made up fake file names a long with a direct link that checks to see if the URL ends with. The hard-code PHP functions very well and is fast however with the MVC one, it is pretty slow at the same time some of my style sheets and javascript doesn’t work. Both have the same script, but I want to move the hard-code PHP one to an MVC logic. 1 that uses MVC and 1 that uses hard-code PHP.
0 Comments
Read More
Leave a Reply. |