Good development practices (Use of Float, Brs, Api)

Asked

Viewed 109 times

0

I would like some views on best practice in development, because I am an amateur in the subject and I would like you to clarify some doubts.

  1. When I am working on the layout I use many BR tags and Floats to organize the layout, is this the right or is there better ways? (had seen on a website where the developer used a css class that defined width:100%, so he could jump line like the BR tag just by setting this class to the Divs)

  2. The use if Apis, I started using a yahoo weather forecast Apis, it provides some ways to get feedback, such as php and javascript, which of the ways performs best? I’m using php only I was in doubt if when I’m consuming the api if the loading of the site can be impaired since php runs first and maybe the server waits for the answer to continue processing the page.

  • 2

    Dunga, try to break this question down into 3 so it doesn’t get too broad and avoid answers based on opinion. your question was well formulated, but this is what is perceived, it can happen that a person knows how to answer one or two questions well and the answer ends up being incomplete

  • I was able to narrow it down to two questions just to be more objective.

2 answers

2


1- No doubt avoid using BR, use css for this (padding or margin).. It is a problem to use this type of css tags/property because if you are doing the template for mobile and desktop you will find problems to put the content in the correct place, because the given space is relative to the size of the device that sees the content. In some cases it makes sense to use br if it is a text for example. My advice is to use a framework to know the basics of content-based creation rather than device-based. Examples: http://getskeleton.com/ or a more complete and better known http://getbootstrap.com

2- I advise two ways:

  • If you want maximum performance in your site’s response time, do two things.. one where it shows the page normally(action1) and the other that serves to go to the api (Ação2). Example: I visit the page with content with a load time of 1.5s when finishing this load, by AJAX make a request to Ação2, which in turn makes a request to the api (by php) This method has the advantage of working only with PHP, apart from the small part of AJAX that makes the request, with this, in my opinion has more control over everything.
  • The other way is to have only one action, according to the above logic, with this you don’t have to use JS to make requests. This way is useful if the API is very fast, I usually use this way when the API is mine (is on the same server) and do not waste response time

Hug and good luck!

  • I forgot to mention, google and the user likes to see something right away, so it’s good to always download the load time of a page, even if you have to carry things slowly ;)

  • Thanks for the tips, another help your...when I use float the object ends up leaving the normal flow of the page, so when a developer uses float to organize the layout.. it uses float on all elements?

  • Yes, if you use float you have to use it on all elements, because those that don’t have float will be there "lost".. You rarely have to use a float, only in specific cases, like buttons on the right and left side.. What controls whether an element goes "down" or "side" is the width of the "window".

  • Because I use float too much for the organization of the Brazilian layout, I always had difficulties in aligning horizontally Ivs, however I am using display:inline and putting the elements inside a container div with width;100%, I feel less amateur with this practice than using float at all.

  • Yes.. over time will find better ways to get the result :) ...

1

1)The BR tag skips a line, no problem in using tag
however its layout cannot be based on skipped lines or not. Try to use CSS for this, preferably create css classes and apply them to the elements instead of using the style attribute in each element of the page, this will make the code easier to maintain and more legible, not to mention the saving of writing and final size. Study margin and padding (CSS), they are the correct ones when you want to distance one thing from the other.

2)You can use float without problems, it is with yourself that you direct the orientation of the element. But always look to use float in a DIV. Always try to keep your code encapsulated in Divs, so you can better control the content and have a better organization.

3) The consumption of this API is almost irrelevant, because it is a processing outside your page, you just get the result. Now if the API takes too long to respond, there’s not much to do. Javascript will always be faster than anything when the subject is web, since it is a scripting language already understood by the browser. PHP has its advantages just like javascript.

4) Try to separate things, css in the head and script at the end of the page inside the body of the page. This way the page is displayed before loading the scripts.

I strongly advise you to learn HTML, CSS and Javascript first, be good at those 3. When you know true javascript, you will have a very easy future with web development.

  • Thanks for the information, I’ve been developing for some time, but I’m kind of self-taught and although I have a reasonable knowledge in languages I realize that in my layouts it seems that has a lot of gambiarra, absurd margins, so I always try to find good practices, as well as facilitating development aid in maintenance.

  • @Dungacardoso knows bootstrap? It can give you a monstrous help with layout. Nowadays no one else is reinventing the wheel with layout. It’s important to know how to do it, know what each thing in css does and so on. But it’s much more productive to use bootstrap or another css framework. http://getbootstrap.com/

  • Rocha, I just heard, I’m one of those who prefer the raw form than using frameworks for more learning, as the site I’m developing is very simple ends up that I’m avoiding using framework to do few functions, even so I will look for more inform me about the bootstrap..

  • @You good piece of shit! But do not reject them, bootstrap is practically essential in any real project you will get, it is mandatory item for web devs :D Good studies, you are already in the right direction!

  • Rocha...I gave a little research...I found it very interesting...but I only intend to use framework in larger and much more complex projects. Thanks

Browser other questions tagged

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