Minified pages and processing for each request

Asked

Viewed 124 times

10

If I want to minify an HTML page from PHP I will be more winning or losing?

More clearly: I want to keep the formatting and practicality for when editing the page, preserving the edentation. But I also worry about page loading, since in the development it is becoming heavier than I would like, so a solution is to minify and save some Kbs by removing all that is unnecessary for the user to download the page. Similarly with CSS and JS.

But since I wanted to do this with PHP (generate an output by removing the waste), I wondered if I would spend more time processing the page than if it had not minified and the download was made.

I understand that this depends on several factors, but I would like to consider large volumes of information (about 2MB non-minified and 1.2MB minified), which is almost 60% difference in size. What are the factors that would slow down the processing of the page?

There are other options to make the page light?

  • 1

    Really, just measuring the performance of your specific case to know, but minify on-the-fly at each request does not seem a good idea in general terms. You have come to consider the option to save minified pages in cache for a period?

  • I do not know if 'chachear' the pages is a good idea, it is updated with a certain daily frequency in a fickle way and I imagine that it would generate problems in this specific case.

  • 1

    It is worth "minify" the HTML if you want to save the maximum in bandwidth. The processing is fast and is very good mainly for slow connections. In PHP, it is easy, just use a combination of ob_start to get the original HTML + str_replace to eliminate spaces and line breaks + preg_replace to delete comments. If you do not use CSRF tokens or redirects, you can cache the HTML on the server. But there are some priorities before that, like Gzip, HTTP cache, optimizing images, combining JS and CSS, using CSS sprites, using a CDN if possible, etc

  • I edited my answer clarifying your doubt

2 answers

3

Do you already have the site running on a public URL (or can you temporarily open it for public Internet testing)? You can use the Pagespeed Insights; it will give you a more accurate notion about where to earn performance.

My personal experience is that you have to first ensure that your server is compressing the files it sends; this will give you a much higher performance gain than taking indentation at a much lower cost in electricity and phosphate.

  • I don’t have control over the server because it’s something far beyond my purview, but I agree with you!

3


You should Minificar and Compactar (note that they are different things) the HTML, CSS and JS of your site along with the images, but I work with Dwoo Templates I maintain a version without minification for work and other minified, note that pages are dynamic even so they remain minified since the template is minified.

  • Minificar: Would remove whitespace (I also remove some useful quotes (when they are useless, e.g.: when there is only one class in the attribute class)) (usually reduces 15%).
  • Compress: Would compress even, using Gzip, natively enabled on Nginx (usually reduces some 50%).
  • File Merge: Merge All . css and . js in a single file (When distributing the page) including library files (watch for interference between variables), the Rails Framework does this almost transparently to users.

Tools: Pagespeed Insights

HTML Compressor (Features Many advanced HTML compression options).

Compress My code (Compress HTML, CSS and JS).

OBS: Clarifying the doubts: When I speak "Compression" would compress the file itself (type .rar .zip) where at the end of the process (Gzip compression and decompression) there is no modification of its file contents. already in the minification there is no file compression . js and . css (type .rar .zip) and yes a useless content removal for the browser.

  • Now I was confused. kk Minification would not be a form of compression? I always had this impression. My goal is not to take away productivity, so possibly I would have a folder for development and the root folder. Root would load the minified files automatically, preventing me from having to minify the file every time it was ready. I am not using any server-side framework for a project limitation.

  • Opa clarifying the doubts: When I speak "Compression" would compress the file itself (type .rar .zip) where at the end of the process not the modification of its file contents.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.